CSS3选择器:nth-child和:nth-of-type之间的差异
来源:互联网 发布:温岭麻将胡头算法 编辑:程序博客网 时间:2024/05/02 19:50
咋一看,:nth-child和:nth-of-type 比较相似,但是两者区别还是比较大的。先来看他们相似的地方:
<!--:nth-child--><style type="text/css"> p{border:1px solid red;height:20px;} p:nth-child(2){background:blue;}</style>
<!--:nth-of-type--><style type="text/css"> p{border:1px solid red;height:20px;} p:nth-of-type(2){background:blue;}</style>
<body> <p>p1</p> <p>p2</p><!--选中这个--></body>
两个选择的效果图相同,如下图:
但是在两个P标签前面加一个span标签,则两则选择的对象就不一样:
<body> <span>span</span> <p>p1</p> <p>p2</p><!--选中这个--></body>
效果如下:
:nth-child(2)的效果
:nth-of-type(2)的效果
由效果图看出两则区别,用口水话解释下:
E:nth-child(2)有两个约束:
1、父级元素下的第二个元素
2、并且第二元素必须是E元素
E:nth-of-type(2)有一个约束:
1、父级元素下的第二个E元素,也就是说不管E元素前面有多少个其他元素,它只会找到第二个E元素
0 0
- CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3选择器:nth-child和:nth-of-type之间的差异
- CSS3选择器:nth-child和:nth-of-type之间的差异(转)
- CSS3选择器:nth-child和:nth-of-type之间的差异
- :nth-child和:nth-of-type之间的差异
- css3中nth-child选择器和nth-of-type选择器的区别
- CSS3的nth-child() 和nth-of-type()选择器,表格奇偶行变色
- CSS3中:nth-child和:nth-of-type的区别
- CSS3中:nth-child和:nth-of-type的区别
- css3 :nth-child和:nth-of-type的区别
- CSS3伪类选择器nth-child和nth-of-type浅析
- CSS3 :nth-child() 与:nth-of-type()
- CSS3—nth-child()和nth-of-type()
- css3之nth-child和nth-of-type
- CSS3的nth-child选择器
- CSS3中:nth-child()和nth-of-type()的却别
- CSS3中:nth-child和:nth-of-type的区别深入理解
- 入门Webpack,看这篇就够了
- 计算24点有什么窍门或技巧吗?
- linux 内核中的 bitmap
- Android 开发SDK与ADT的区别
- LeetCode 8. String to Integer (atoi)
- CSS3选择器:nth-child和:nth-of-type之间的差异
- springmvc、spring和mybatis
- leetcode刷题记录
- mybatis 并发问题解决,参考hibernate
- 参考文献
- 小谈网络游戏同步
- 润乾报表样式的CSS控制
- mac重装系统之Maven安装
- NOIP2016提高组Day1T3 换教室