久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是否可以使用當前瀏覽器使用偽類來檢測某個類

Is it possible using current browsers to use pseudo-classes to detect first and last of a certain class?(是否可以使用當前瀏覽器使用偽類來檢測某個類的第一個和最后一個?)
本文介紹了是否可以使用當前瀏覽器使用偽類來檢測某個類的第一個和最后一個?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如果你有 HTML:

<section class="column">
  <p> Some Test </p>
  <p> Some Test </p>
  <p> Some Test </p>
</section>

<section class="column">
  <p> Some More Test </p>
  <p> Some More Test </p>
  <p> Some More Test </p>
</section>

<section class="someotherclass">
  <p> Some More Test </p>
  <p> Some More Test </p>
  <p> Some More Test </p>
</section>

和 CSS:

.column:last-child { background:red; }

http://jsfiddle.net/WYu24/

有沒有辦法讓 :last-child 選擇器選擇最后一次出現的類?

Is there a way to make the :last-child selector pick up the last occurrence of a class?

推薦答案

目前在 CSS 中沒有快捷語法或偽類來查找具有某個類的第一個或最后一個子級.1

Currently there is no shortcut syntax or pseudo-class in CSS for finding the first or last child having a certain class.1

我使用一種覆蓋技術來設置具有特定類的第一個孩子的樣式,我在 this answer.但是,由于同級組合器的工作方式,這種技術不能應用于具有特定類的最后一個孩子.

I use an overriding technique to style the first child with a certain class, which I describe in heavy detail in this answer. However, due to how sibling combinators work, this technique cannot be applied for the last child having a certain class.

我不知道有任何純 CSS 方法來定位最后一個具有特定班級的孩子.您必須使用 JavaScript 或重組您的標記才能做到這一點.如果確實有一個這樣的元素,那么使用 jQuery,您可以簡單地使用 :last 選擇器添加一個類,然后您可以使用 CSS 設置樣式:

I do not know of any pure CSS way to target the last child having a certain class. You have to use JavaScript or restructure your markup in order to do that. If there is exactly one such element, then using jQuery you can simply use the :last selector to add a class, which you can then style with CSS:

$('.column:last').addClass('last');

.column.last { background:red; }

jsFiddle 預覽

1 有一些在 Selectors 4 中提出了新的偽類,這將符合要求,但瀏覽器將在幾個月后或直到規范更穩定之前開始實施它,即便如此我們也不知道這些偽類是否-classes 會堅持下去,因為當前的語法看起來很尷尬:

1 There are some new pseudo-classes being proposed in Selectors 4 which would fit the bill, but browsers won't start implementing it for another few months or until the spec is more stable, and even then we don't know if these pseudo-classes are going to stick because the current syntax looks rather awkward:

:nth-last-match(1 of .column) { background:red; }

這篇關于是否可以使用當前瀏覽器使用偽類來檢測某個類的第一個和最后一個?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

CSS selector when :target empty(:target 為空時的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個 HTML 標簽使用相同的 ID?)
主站蜘蛛池模板: 欧美精品一区二区三区一线天视频 | 九九久久久 | 国产午夜精品久久久 | 欧美一区二区另类 | 视频一区在线观看 | 亚洲免费久久久 | 日韩精品成人一区二区三区视频 | 亚洲视频区 | 亚洲在线电影 | 激情五月婷婷在线 | 国产高潮好爽受不了了夜色 | 国产日韩欧美在线观看 | 日韩精品免费一区二区在线观看 | 蜜臀久久99精品久久久久野外 | 亚洲精品片 | 国产中文区二幕区2012 | av福利网站 | 一区二区三区av夏目彩春 | .国产精品成人自产拍在线观看6 | www.精品国产| 国产在线观看福利 | 国产精品色| 婷婷久久精品一区二区 | 欧美福利视频 | 九九亚洲 | 国产网站在线播放 | 日日碰狠狠躁久久躁婷婷 | 国产乱码久久久 | av在线电影网站 | 欧美男男videos| 日韩一区二区三区在线视频 | 欧美精品久久久久 | 中文字幕日韩欧美一区二区三区 | 国产成人一区二区三区 | 国产91综合 | 亚洲网站在线观看 | 91精品国产色综合久久 | 国产精品美女www爽爽爽视频 | 天天干狠狠操 | 日韩在线观看中文字幕 | 一区二区精品电影 |