html - 为什么不是 :last-of-type working on tumblr?

标签 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/

上一篇:javascript - 单击其内容时 Materialise UI 下拉菜单关闭

下一篇:javascript - 测量单击iFrame顶部的不可见DIV?

相关文章:

javascript - 删除鼠标悬停时的 Canvas 矩形边框

css - 固定导航栏导致页面内的按钮不起作用

jquery - 使用 jQuery 切换 div 的高度

PHP成员(member)资格时间和有效期

html - tomcat6 上的 webapp 中的 SVG 在 IE9 中不起作用

html - 边框不会在 Internet Explorer 中显示

html - 如何将标题背景图像保持在视口(viewport)中的恒定水平点

java - 如何以最少的等待时间加速 Java Selenium Script

css - 在 Word 中设置单个字母的样式

Contact-Form 7 插件的 CSS,在整个网站上没有被平等地选择