[CSS3] :nth-child的用法

來源:互聯網
上載者:User

標籤:需要   大於   等於   表示   pre   round   n+1   ret   數字   

: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}

:nth-child的這些用法在實際中很用得著,不用單獨給需要選取的標籤加上ID或Class
 
 
 

[CSS3] :nth-child的用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.