数据列表的模块,经常会遇到最后一个元素不需要某某某属性,我们通常会写两行代码,通用属性一行,另外加一行CSS专门为最后一个元素去掉相关属性,其实这复杂了,学习:not(:last-of-type)后,发现一行搞定。直接上DEMO:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>学习CSS3中的技巧之:not(:last-of-type)</title>
</head>
<style>
/*正常写法
.posts {
list-style: none;
width:400px;
margin: 0;
padding: 20px;
margin: 4rem auto;
background: #f8f8f8;
}
.posts li{
border-bottom: 1px solid #000;
margin-bottom: .5rem;
padding-bottom: .5rem;
}
.posts li:last-of-type{
border-bottom: 0;
margin-bottom: 0;
padding-bottom: 0;
}
*/
.posts {
list-style: none;
width:400px;
margin: 0;
padding: 20px;
margin: 4rem auto;
background: #f00;
}
.posts li:not(:last-of-type){
border-bottom: 1px solid #000;
margin-bottom: .5rem;
padding-bottom: .5rem;
}
</style>
<body>
<ul class="posts">
<li>Web前端之家</li>
<li>前端之家</li>
<li>前端之家</li>
<li>前端之家</li>
<li>前端之家</li>
</ul>
</body>
</html> 






网友评论文明上网理性发言 已有0人参与
发表评论: