CSS3 :nth-child(n)使用注意
2018-02-07 14:14
549 查看
p:nth-child(n) ---->选中p元素,且该p元素必须是某个父元素下的第n个子元素
注意:n是从1开始的
如下代码,p:nth-child(1),只会选中第二个div中第一个子元素p;
不会选中第一个div中的第一个p,因为第一个div中第一p元素不是第一个子元素
<style> p:nth-child(1){ color:red } </style> <div style="border:1px solid"> <span>div span中第一个段落。</span> <p>div 中第一个段落。</p> <p>div 中的最后一个段落。</p> </div><br> <div style="border:1px solid"> <p>另一个 div 中第一个段落。</p> <p>另一个 div 中的最后一个段落。</p> </div>
正方向范围
li:nth-child(n+6)
选中从第6个开始的子元素
负方向范围
:nth-child(-n+9)
选中从第1个到第9个子元素。使用 :nth-child(-n+9) ,就相当让你选中第9个和其之前的所有子元素
前后限制范围
:nth-child(n+4):nth-child(-n+8)
选中第4-8个子元素。使用 nth-child(n+4):nth-child(-n+8) 我们可以选中某一范围内子元素,上面的例子里是从第4个到第8个子元素
奇数、偶数位
:nth-child(odd)
:nth-child(even)
隔选择子元素
:nth-child(3n+1),选择1,4,7,10
范围高级用法
nth-child(n+2):nth-child(odd):nth-child(-n+9)
使用 nth-child(n+2):nth-child(odd):nth-child(-n+9) 我们将会选中的子元素是从第2位到第9位,并且只包含奇数位。
分类: CSS3
标签: CSS3
相关文章推荐
- CSS3 :nth-child(n)使用注意
- CSS3:nth-child使用总结
- Jquery下:nth-child(an+b)的使用注意
- 使用CSS3 :nth-child(n) 選取器教學
- CSS3 nth-child的使用
- CSS3 :nth-child() 选择器的使用
- Jquery下:nth-child(an+b)的使用注意
- cSS3 伪类:nth-child 的使用方法
- CSS3选择器:nth-child和:nth-of-type之间的差异(转)
- CSS3中:nth-child和:nth-of-type的区别深入理解
- CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3属性(3):nth-child()属性
- CSS3 :nth-child()伪类选择器
- CSS3 :nth-child()伪类选择器
- 深入理解css3中nth-child和 nth-of-type的区别
- 使用css属性:nth-child(n)匹配选择第n个子元素
- CSS3 :nth-child() 选择器
- CSS3 :nth-child() 选择器---挖坑
- CSS3中first-child、last-child、nth-child、nth-last-child
- CSS3中first-child、last-child、nth-child、nth-last-child