CSS3伪类选择器:nth-child(n)及:nth-of-type(n)使用区别探究总结
2018-01-30 11:20
846 查看
标签的情况
tag:nth-child(n):很好理解。1.各层级中的第n个元素;2.且该元素是tagtag:nth-of-type(n):和上面不一样。1.在各层级中第n个出现的tag元素,与它是在父级下的第几个位置无关。
类的情况
.class:nth-child(n):和tag模式基本是一致的。1.各层级中的第n个元素;2.是class类.class:nth-of-type(n):和tag模式就有些区别了。1.对层级中存在的标签,分别对应找出第n个出现的标签,2.是class类
示例代码
<!DOCTYPE html> <html> <head> <title>temdiv</title> <style> .item:nth-of-type(2){ color:red; } </style> </head> <body> <span>1</span> <div>2</div> <div><span class="item">type111,child111</span></div> <div><div class="item">type111,child111</div></div> <div class="item">6</div> <div>7</div> <div class="item">8</div> <span class="item">type222</span> <div class="item">10</div> <div>11</div> <div class="item">12</div> <span>13</span> <div> <span>14</span> <span class="item">type222,child222</span> <span class="item">16</span> <div class="item">type111</div> <div class="item">type222</div> <div class="item">19</div> </div> </body> </html>
相关文章推荐
- css 伪类选择器 :nth-child(n) 与:nth-of-type(n)的区别
- CSS nth-child、first-child、last-child、nth-of-type、first-of-type和last-of-type选择器使用
- CSS nth-child、first-child、last-child、nth-of-type、first-of-type和last-of-type选择器使用
- CSS中nth-child和nth-of-type的简单使用
- CSS :nth-child与:nth-of-type选择器
- CSS 选择器 :last-child与:last-of-type的区别
- css3中nth-child选择器和nth-of-type选择器的区别
- CSS 中 nth-child 和 nth-of-type 的区别
- css :nth-child和:nth-of-type的区别
- CSS中nth-child和nth-of-type的区别
- css nth-child和nth-type-of 区别
- css nth-child(n)和nth-of-type(n)区别
- CSS3子元素选择方法nth-child和nth-of-type
- css :fitst-of-type与:first-child的区别
- :nth-child()和:nth-of-type(n)区别
- :nth-child 和 :nth-type-of 的区别
- :nth-child和:nth-of-type的区别
- CSS3伪类选择器:nth-child()
- 选择器的使用(nth-of-type和nth-last-of-type选择器)
- css3 nth-child 与 nth-of-type 的区别