使用:not(:last-of-type)简单方便,再也不要麻烦的单独使用:last-of-type了,不错!
应用场景:平时我们的列表一般都会有分割线,但是最后一个列表没有分割线等。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>CSS中:not(:last-of-type)的作用</title>
</head>
<style>
.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>123123</li>
<li>123123</li>
<li>123123</li>
<li>123123</li>
<li>123123</li>
</ul>
</body>
</html> 


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