: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 > <article id="com21"></article> <article id="com20"></article> <article id="com19"></article> <div > hello </div></div>


