【Web前端】CSS 选择器之 last-child 与 last-of-type
来源:互联网 发布:虚拟机网络配置 编辑:程序博客网 时间:2024/06/05 05:43
前言
今天在做 demo 时,last-child 与 last-of-type 发生了混淆,在此记录。
last-child
先看一下 w3school 中的解释:
:last-child p:last-child 选择属于其父元素最后一个子元素每个 <p> 元素。
last-of-type
:last-of-type p:last-of-type 选择属于其父元素的最后 <p> 元素的每个 <p> 元素。
比较与区别
在某些情况下,两者的使用效果是一样的,如果理解不透彻,就会出现一些问题。
例子一:
<div> <p>一</p> <p>二</p> <p>三</p> <p>四</p> </div>
p:last-child ,p:last-of-type 将会作用到第四个 p 元素 <p>四</p>
例子二:
<div> <p>一</p> <p>二</p> <p>三</p> <a>四</a> </div>
p:last-child 将匹配不到任何对象;
而 p:last-of-type 则只会作用到第三个 p 元素 <p>三</p>
因为第四行,也就是最后一个元素是不同类型的 a 元素。
总结
许多东西还是纸上得来终觉浅,练习的时候才会发现小问题不断。
1 0
- 【Web前端】CSS 选择器之 last-child 与 last-of-type
- 第二章 CSS3新增的选器之 选择器 last-child last-of-type区别
- first-child first-of-type last-child last-of-type 伪类选择器总结
- jQuery 选择器 first-child和first-of-type、 last-child和last-of-type的区别
- last-of-type选择器
- 【CSS3】last-of-type选择器
- nth-last-of-type选择器
- css中的first-child nth-child nth-last-child() 和:nth-of-type(n)
- css选择器——:first/last-of-type
- :last-child与:last-of-type你只是会用,有研究过区别吗?
- :last-child 选择器
- CSS3 :nth-child() ,nth-of-type(),nth-last-child() ,nth-last-of-type()
- 【CSS3】nth-last-of-type(n)选择器
- css:first-child、last-child、nth-child、 nth-last-child
- 【CSS3】---last-of-type选择器+nth-last-of-type(n)选择器
- Jquery 选择器(:last-child)详解
- :last-of-type | CSS属性参考
- CSS :nth-child与:nth-of-type选择器
- ionic -- 仿微信通讯录
- Running Dubbo On Spring Boot
- C++ 虚函数表解析
- JAVA List中剔除空元素(null)的方法
- javaScript脚本
- 【Web前端】CSS 选择器之 last-child 与 last-of-type
- css绝对定位、相对定位和文档流的那些事
- 对象学习
- python 安装easy_install方法
- 鸟哥的linux私房菜学习笔记《四》忘记root密码
- 51nod 1276 岛屿的数量(思维)
- Thinkphp+同步条件查询+分页应用
- iOS混合开发调试秘籍
- 校招笔试面试常考的数据库知识