詳解CSS中:nth-child的用法


下面我將用幾個典型的實例來給大家講解:nth-child的實際用途:

Tips:還用低版本的IE瀏覽器的哥們請繞過!

:nth-child(2)選取第幾個標簽,“2可以是你想要的數字”

.demo01 li:nth-child(2){background:#090}

 :nth-child(n+4)選取大於等於4標簽,“n”表示從整數,下同

.demo01 li:nth-child(n+4){background:#090}

:nth-child(-n+4)選取小於等於4標簽

.demo01 li:nth-child(-n+4){background:#090}

:nth-child(2n)選取偶數標簽,2n也可以是even

.demo01 li:nth-child(2n){background:#090}

:nth-child(2n-1)選取奇數標簽,2n-1可以是odd

.demo01 li:nth-child(2n-1){background:#090}

:nth-child(3n+1)自定義選取標簽,3n+1表示“隔二取一”

.demo01 li:nth-child(3n+1){background:#090}

:last-child選取最后一個標簽

.demo01 li:last-child{background:#090}

:nth-last-child(3)選取倒數第幾個標簽,3表示選取第3個

.demo01 li:nth-last-child(3){background:#090}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM