久久久久久久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?)
主站蜘蛛池模板: 国产一区二区美女 | 北条麻妃av一区二区三区 | 欧美精品三区 | 午夜视频在线免费观看 | 亚洲激精日韩激精欧美精品 | 欧美视频一区二区三区 | 日韩视频一区二区在线 | 亚洲成人中文字幕 | 天堂网色 | 国产一区二区观看 | 亚洲欧美精品久久 | 久久久久久久av | 国产黄色网址在线观看 | 在线中文字幕日韩 | 国产一区免费 | 青草久久免费视频 | 国产一区二区三区免费观看在线 | 青青久视频 | 国产精品国产a级 | 午夜精品一区二区三区在线观看 | 国产精品视频一区二区三区不卡 | 精品国产乱码久久久久久影片 | 亚洲视频一区在线观看 | 日本小视频网站 | 人人鲁人人莫人人爱精品 | 久久天堂网 | 国产日韩一区二区 | 天堂在线www | 亚洲欧美综合精品久久成人 | 97精品国产| 欧美在线视频一区二区 | 亚洲一区视频 | 精品亚洲一区二区三区 | 国产视频1区 | www精品美女久久久tv | 97影院2 | 免费一区 | 久久久久网站 | 亚洲精品自在在线观看 | 日韩一区二区三区视频 | 99久久久久久久久 |