<分区>
标签 html css css-selectors
<分区>
尽管将 :last-of-type
限制为某个 div
,但当我在该 div 下添加另一个 div 时,:last-of-type
类(class)突然被取消。有什么原因吗?
.container {
width: 400px;
border-bottom: 1px solid #111;
}
.container:last-of-type {
border-bottom: 0;
}
<div class="entry">
<div class="container">
{block:Posts} ....... {/block:Posts}
</div>
<div class="pagination">....</div>
</div>
使用这段代码,如果我删除了 .pagination
div,:last-of-type
正常工作并删除了 border-bottom
.
但是如果我添加 .pagination
div,突然 :last-of-type
不起作用,即使 .pagination
div 不包含在容器类中。
有办法解决吗?或者选择 .container
div 的最后一个 div 而没有 .pagination
类影响它?
最佳答案
您正在选择 .container
,而不是它的最后一个子项。 .container:last-of-type
的形式选择任何属于 .container
类的最后一个类型。通过插入一个空格(通用后代选择器)或右尖括号 (>)(直接后代选择器),您现在可以在 .container< 类的任何元素中选择给定类型的最后一个
.
.container > :last-of-type
不过,这可能不是您的最佳选择。您应该考虑 last-child 是否更有意义。例如,如果您在某个时刻引入了不同类型的元素,则将选择每种类型的最后一个。
关于html - 为什么不是 :last-of-type working on tumblr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48476831/