CSS3中:nth-child和:nth-of-type的区别深入理解
来源:互联网 发布:淘宝电子发票怎么打印 编辑:程序博客网 时间:2024/05/21 21:40
关于:nth-child和:nth-of-type的区别之前一直没太注意,经深入理解才发现里面其实暗藏玄机
关于:nth-child和:nth-of-type的区别之前一直没太注意。最近打算深入了解一些CSS3,才发现里面其实暗藏玄机。
:nth-child可以选择父元素下的字元素,:nth-of-type也可以。但是它们到底有什么区别呢?
其实区别很简单::nth-of-type为什么要叫:nth-of-type?因为它是以"type"来区分的。也就是说:ele:nth-of-type(n)是指父元素下第n个ele元素,
而ele:nth-child(n)是指父元素下第n个元素且这个元素为ele,若不是,则选择失败。
这里附上一个小例子:
<div>
<ul class="demo">
<p>zero</p>
<li>one</li>
<li>two</li>
</ul>
</div>
上面这个例子,.demo li:nth-child(2)选择的是<li>one</li>节点,而.demo li:nth-of-type(2)则选择的是<li>two</li>节点。
:nth-child可以选择父元素下的字元素,:nth-of-type也可以。但是它们到底有什么区别呢?
其实区别很简单::nth-of-type为什么要叫:nth-of-type?因为它是以"type"来区分的。也就是说:ele:nth-of-type(n)是指父元素下第n个ele元素,
而ele:nth-child(n)是指父元素下第n个元素且这个元素为ele,若不是,则选择失败。
这里附上一个小例子:
<div>
<ul class="demo">
<p>zero</p>
<li>one</li>
<li>two</li>
</ul>
</div>
上面这个例子,.demo li:nth-child(2)选择的是<li>one</li>节点,而.demo li:nth-of-type(2)则选择的是<li>two</li>节点。
阅读全文
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的区别
- css3中nth-child选择器和nth-of-type选择器的区别
- nth-child和nth-of-type区别
- :nth-child 和 :nth-type-of 的区别
- :nth-child 和 :nth-type-of 的区别
- :nth-child和:nth-of-type的区别
- 关于:nth-child和:nth-of-type的区别
- :nth-child和:nth-of-type的区别
- nth-child和nth-of-type的区别
- :nth-child和:nth-of-type的区别
- nth-of-type和nth-child的区别
- nth-of-type和nth-child的区别
- css :nth-child和:nth-of-type的区别
- CSS3中:nth-child()和nth-of-type()的却别
- shell脚本实现彩色进度条
- 学习博客园开源代码笔记(startup页面)
- 怎么样让插入div成第一个
- yii2 验证规则的坑
- 线程池
- CSS3中:nth-child和:nth-of-type的区别深入理解
- 27-二叉搜索树与双向链表
- 深度学习之OCR(五)——Attention机制_gradient-based attention
- Server Tomcat v7.0 Server at localhost failed to start
- [LeetCode] 236. Lowest Common Ancestor of a Binary Tree
- python中的 os.mkdir和os.mkdirs
- 图像缩放的双线性内插值算法的原理解析
- CentOS7 设置静态IP
- python 赋值