CSS3---结构性伪类选择器—last-child
2015-05-04 21:07
267 查看
结构性伪类选择器—last-child
“:last-child”选择器与“:first-child”选择器作用类似,不同的是“:last-child”选择器选择的是元素的最后一个子元素。例如,需要改变的是列表中的最后一个“li”的背景色,就可以使用这个选择器,ul>li:last-child{background:blue;}
示例演示
在博客的排版中,每个段落都有15px的margin-bottom,假设不想让博客“post”中最后一个段落不需要底部的margin值,可以使用“:last-child”选择器。
HTML代码:
<div class="post"> <p>第一段落</p> <p>第二段落</p> <p>第三段落</p> <p>第四段落</p> <p>第五段落</p> </div>
CSS代码:
.post { padding: 10px; border: 1px solid #ccc; width: 200px; margin: 20px auto; } .post p { margin:0 0 15px 0; } .post p:last-child { margin-bottom:0; }
演示结果:
![](http://img.mukewang.com/531eb9cb0001428002760188.jpg)
相关文章推荐
- 【CSS3】---结构性伪类选择器-first-child+last-child
- 【CSS3】---结构性伪类选择器—nth-child(n)+nth-last-child(n)
- 【CSS3】---结构性伪类选择器—nth-child(n)+nth-last-child(n)
- CSS3---结构性伪类选择器—nth-last-child(n)
- 【CSS3】结构性伪类选择器—last-child
- 【CSS3】结构性伪类选择器—nth-last-child(n)
- 【CSS3】---结构性伪类选择器-first-child+last-child
- 【CSS3】---结构性伪类选择器—nth-child(n)+nth-last-child(n)
- 结构性伪类选择器—nth-last-child(n)
- CSS3---结构性伪类选择器—first-child
- CSS3---结构性伪类选择器—nth-child(n)
- 【CSS3】结构性伪类选择器—nth-child(n)
- 结构性伪类选择器—last-child
- Atitit.隔行换色 变色 css3 结构性伪类选择器
- css3-属性、伪类、nth-child选择器
- jQuery实现隔行变色、悬停变色 ( CSS3伪类选择器:nth-child() )
- CSS3 伪类选择器 nth-child() 的用法
- Atitit.隔行换色 变色 css3 结构性伪类选择器
- CSS3:nth-child()伪类选择器,Table表格奇偶数行定义样式
- CSS3---结构性伪类选择器-root