:last-child
仅在有问题的元素是容器的最后一个子元素而不是特定类型的元素的最后一个元素时起作用。为此,你想要:last-of-type
根据@BoltClock的注释,这仅检查最后一个article
元素,而不检查类为的最后一个元素.comment
。
body {
background: black;
}
.comment {
width: 470px;
border-bottom: 1px dotted #f0f0f0;
margin-bottom: 10px;
}
.comment:last-of-type {
border-bottom: none;
margin-bottom: 0;
}
<div class="commentList">
<article class="comment " id="com21"></article>
<article class="comment " id="com20"></article>
<article class="comment " id="com19"></article>
<div class="something"> hello </div>
</div>