CSS3---nth-of-type(n)选择器
2015-05-04 21:25
941 查看
nth-of-type(n)选择器
“:nth-of-type(n)”选择器和“
:nth-child(n)”选择器非常类似,不同的是它只计算父元素中指定的某种类型的子元素。当某个元素中的子元素不单单是同一种类型的子元素时,使用“:nth-of-type(n)”选择器来定位于父元素中某种类型的子元素是非常方便和有用的。在“:nth-of-type(n)”选择器中的“n”和“:nth-child(n)”选择器中的“n”参数也一样,可以是具体的整数,也可以是表达式,还可以是关键词。
示例演示
通过“:nth-of-type(2n)”选择器,将容器“div.wrapper”中偶数段数的背景设置为橙色。
HTML代码:
<div class="wrapper"> <div>我是一个Div元素</div> <p>我是一个段落元素</p> <div>我是一个Div元素</div> <p>我是一个段落</p> <div>我是一个Div元素</div> <p>我是一个段落</p> <div>我是一个Div元素</div> <p>我是一个段落</p> <div>我是一个Div元素</div> <p>我是一个段落</p> <div>我是一个Div元素</div> <p>我是一个段落</p> <div>我是一个Div元素</div> <p>我是一个段落</p> <div>我是一个Div元素</div> <p>我是一个段落</p> </div>
CSS代码:
.wrapper > p:nth-of-type(2n){ background: orange; }
演示结果:
相关文章推荐
- CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3选择器:nth-child和:nth-of-type之间的差异(转)
- CSS3选择器之nth-of-type
- CSS3选择器:nth-child和:nth-of-type之间的差异
- 【CSS3】---last-of-type选择器+nth-last-of-type(n)选择器
- 【CSS3】---first-of-type选择器+nth-of-type(n)选择器
- css3中nth-child选择器和nth-of-type选择器的区别
- 【CSS3】---last-of-type选择器+nth-last-of-type(n)选择器
- CSS3选择器:nth-of-type
- [css3]CSS3选择器:nth-child和:nth-of-type之间的差异
- 【CSS3】---first-of-type选择器+nth-of-type(n)选择器
- css3 - 选择器first-child、last-child、nth-child、nth-last-child、nth-of-type
- 【CSS3】---last-of-type选择器+nth-last-of-type(n)选择器
- CSS3选择器:nth-child和:nth-of-type之间的差异
- 【CSS3】nth-of-type(n)选择器
- css3选择器——:nth-of-type的测试
- 【CSS3】nth-last-of-type(n)选择器
- CSS3的nth-child() 和nth-of-type()选择器,表格奇偶行变色
- 【CSS3】---last-of-type选择器+nth-last-of-type(n)选择器
- CSS3选择器:nth-child和:nth-of-type之间的差异