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

css :nth-child() :after

css :nth-child() :after(css :nth-child() :after)
本文介紹了css :nth-child() :after的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

:nth-child()after 可以混用嗎?

我有一個 <ol> 項目,我想在 :after 之后添加一些文本.這很好用,但我希望在第 1、第 2 和第 3 項以及第 4、第 5 和第 6 項上使用不同的文本.

I have an <ol> of items and I want to add some text :after. This works fine but I'd then like to have different text on 1st, 2nd and 3rd items and then 4th, 5th and 6th as well.

使用下面的代碼,我最終得到每個 li 后面都有粉紅色的大".

With the below code I end up with every li having 'large' in pink after it.

這對我來說沒有意義,但是我是這個 nth-child 的新手.

This doesn't make sense to me however I am new to this nth-child malarky.

data.html

<ol id="id" class="ui-sortable">
    <li>
        <p>Bacon</p>
    </li>
    <li>
        <p>Bacon</p>
    </li>
    <li>
        <p>Bacon</p>
    </li>

    <!.. repeats -->

    <li>
        <p>Bacon</p>
    </li>
</ol> 

pretty.css

#id li p:after {
    float: right;
    content: 'nom';
}

#id li p:nth-child(1):after,
#id li p:nth-child(2):after,
#id li p:nth-child(3):after {
    content: 'OM';
    color: pink;
}

#id li p:nth-child(4):after,
#id li p:nth-child(5):after,
#id li p:nth-child(6):after {
    content: 'Nom';
    color: blue;
}

我真的不想用 js 來做這件事,因為它只是一個很高興擁有"的功能.

I'd really like not to do this with js as it just a 'nice to have' feature.

我只擔心新的瀏覽器,所以不需要 oldIE 等的解決方法.

I'm only worried about new browsers so no need for workarounds for oldIE etc.

推薦答案

你可以,但是你做錯了..

You can, but you are doing it wrong..

所有 p 元素都在 li 內的問題.所以他們都是他們的 li 容器的第一個孩子.

The issue that that all your p elements are inside li. So all of them are the first child of their li container.

您需要將 nth-child 放在 li 元素上.

You will need to put the nth-child on the li elements.

#id li:nth-child(1) p:after,
#id li:nth-child(2) p:after,
#id li:nth-child(3) p:after {
    content: 'OM';
    color: pink;
}

#id li:nth-child(4) p:after,
#id li:nth-child(5) p:after,
#id li:nth-child(6) p:after {
    content: 'Nom';
    color: blue;
}

<小時>

引用W3C 文檔

:nth-child(an+b) 偽類表示法表示在文檔樹中具有一個+b-1 個兄弟的元素,例如n 的任何正整數或零值,并且具有父元素.

The :nth-child(an+b) pseudo-class notation represents an element that has an+b-1 siblings before it in the document tree, for any positive integer or zero value of n, and has a parent element.

<小時>

更新 1

您也可以使用

#id li:nth-child(-n+3) p:after {
    content: 'OM';
    color: pink;
}

#id li:nth-last-child(-n+3) p:after { /*this means last 3*/
    content: 'Nom';
    color: blue;
}

演示在 http://jsfiddle.net/gaby/4H4AS/2/

更新 2

如果您只希望前六個不同(而不是前 3 個和后 3 個),您可以

If you want the first six only to be different (and not first 3 and last 3) you could

#id li:nth-child(-n+6) p:after { /*this means first 6*/
    content: 'Nom';
    color: blue;
}

#id li:nth-child(-n+3) p:after {/*this means first 3 and since it comes second it has precedence over the previous for the common elements*/
    content: 'OM';
    color: pink;
}

演示在 http://jsfiddle.net/gaby/4H4AS/3/

這篇關于css :nth-child() :after的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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| 精品国产一区探花在线观看 | 亚洲精品一区二区另类图片 | 欧美激情va永久在线播放 | 九九成人 | 黄色在线免费观看 | 亚洲欧美日韩精品久久亚洲区 | 综合国产 | 久久一日本道色综合久久 | 亚洲成人一级片 | 婷婷久久一区 | 精品欧美一区二区在线观看视频 | 欧美成人a | 免费观看一级毛片 | 亚洲免费在线播放 | 午夜精品一区二区三区在线播放 | 免费小视频在线观看 | 精品在线一区 | 四虎最新 | 中文久久| 久久久久se| 国产三区四区 | 黄色在线免费播放 | 成人激情视频免费观看 | 国产激情 | 一区视频 | 久久久久久久网 | 久久久久国产视频 | 亚洲成av人片在线观看 | 亚洲精品日韩精品 | 亚洲va欧美va天堂v国产综合 | av网站观看 | 日本在线免费观看 | 久草成人 | 99免费精品视频 | 亚洲成人av一区二区 | 91久久国产综合久久91精品网站 | 91精品国产一区二区三区 | 福利视频一区 | 亚洲一区中文字幕在线观看 |