打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
详解CSS中:nth
userphoto

2017.05.12

关注

前端的哥们想必都接触过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}

ok,:nth-child的这些用法在实际中很用得着,不用单独给需要选取的标签加上ID或Class,是不是很拉轰!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
CSS3 选择器
CSS3选择器nth-child(n)实现隔几行选择元素
jQuery选择器CSS的用法
CSS3 :nth
6-4 CSS选择器
CSS3学习系列之选择器(二)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服