码迷,mamicode.com
首页 > Web开发 > 详细

[CSS3] :nth-child的用法

时间:2017-06-07 12:42:46      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:需要   大于   等于   表示   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的用法

标签:需要   大于   等于   表示   pre   round   n+1   ret   数字   

原文地址:http://www.cnblogs.com/frost-yen/p/6956055.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!