我有这个结构:
<div id="results">
<div class="post-item">
<div class="post-item-inside"></div>
</div>
<div class="post-item">
<div class="post-item-inside"></div>
</div>
<div class="post-item">
<div class="post-item-inside"></div>
</div>
<div class="post-item">
<div class="post-item-inside"></div>
</div>
<div class="post-item">
<div class="post-item-inside"></div>
</div>
</div>
CSS
:
.post-item {
width: 50%;
padding: 2.5%;
margin: 0 auto;
background: #fff;
}
.post-item-inside {
width: 95%;
padding-bottom: 20px;
border-bottom: 1px solid;
border-color: #d0d1d5;
margin: 0 auto;
}
我想删除最后.post-item-inside
的边框颜色。我试过这个方法:
.post-item:last-child .post-item-inside {
border-bottom: none;
}
但它不起作用。我该如何解决? 谢谢!
答案 0 :(得分:0)
虽然您的代码运行正常,但请尝试以下方法:
#results .post-item:last-child .post-item-inside {
border-bottom: none;
}
也许您的网站中的其他.post-item
元素比#results
答案 1 :(得分:0)
答案 2 :(得分:0)
我使用border-top
和first-child
更改了代码:
.post-item {
width: 50%;
padding: 2.5%;
margin: 0 auto;
background: #fff;
}
.post-item-inside {
width: 95%;
border-top: 1px solid;
border-color: #d0d1d5;
margin: 0 auto;
}
#results .post-item:first-child .post-item-inside {
border-top: none;
}
它有效!