CSS - 选择第三个 DL



我的标记是

<div class="gallery">
 <dl class="item">content 1</dl>
 <dl class="item">content 2</dl>
 <dl class="item">content 3</dl>
 <br style="clear: both">
 <dl class="item">content 4</dl>
 <dl class="item">content 5</dl>
 <dl class="item">content 6</dl>
</div>

现在我想选择列表中的第三个 DL。内容 3内容 6,但此 CSS 仅选择内容 3,而不选择内容 6。"DL"之间的"BR"使某些东西损坏。

.gallery :nth-child(3) {
    margin-right: 0;
}

有什么想法吗?

谢谢

改用dl:nth-of-type(3n)来排除br

.gallery dl:nth-of-type(3n) {
    margin-right: 0;
}

或者,使用另一个:nth-child()规则将清除应用于之后的下一个dl,并删除该br,因为它不需要:

.gallery dl:nth-child(3n) {
    margin-right: 0;
}
.gallery dl:nth-child(3n+1) {
    clear: both;
}

最新更新