【问题标题】:Is there a way to dynamically add a "last" class to the last post appearing in a Tumblr tag page?有没有办法将“last”类动态添加到出现在 Tumblr 标签页面中的最后一篇文章中?
【发布时间】:2022-01-04 19:04:57
【问题描述】:

我想知道是否可以在出现在 tumblr 标签页面中的最后一篇文章中添加一个“last”类,以便能够在 css 中对其进行自定义?

目标如下:假设某个标签有 3 个帖子,所以当我在该标签页面中导航时,会出现 3 个帖子,一个在另一个之下。我希望前两个由位于每个帖子正文底部的线分隔,但页面底部的最后一个不应在其底部有分隔线,所以我想我需要一个特定的类因为是最后一篇所以发帖。

谢谢。

【问题讨论】:

  • 你可以只使用css选择器:last-of-type:nth-child(last)我不知道你的标记是什么,但我在这里做了一个粗略的例子:jsfiddle.net/lharby/39ap851L这将在任何页面上运行但是发布内容,所以如果你只想定位标记的帖子,你必须做更多的诡计。
  • 你有没有尝试过任何东西?
  • 有效!!你能把它写成答案而不是评论,这样我就可以选择它作为解决方案?谢谢
  • 几天前发布的。如果有帮助,请投票。

标签: tumblr tumblr-themes tumblr-html


【解决方案1】:

根据我的评论,您可以通过简单地使用 css 选择器 :last-of-type:nth-child(last) 来实现这一点

这是一个例子。

HTML:

<div id="posts">
    <div class="post">
        Post 1
    </div>
    <div class="post">
        Post 2
    </div>
    <div class="post">
        Post 3
    </div>
</div>

CSS:

#posts .post {
    margin-bottom: 20px;
    border-bottom: 2px solid #444;
}
#posts .post:last-of-type {
    background-color: orange;
    border-bottom: none;
}

这里有一个jsfiddle:https://jsfiddle.net/lharby/39ap851L/

所以每个帖子都有一个底部边框,但是对于最后一个类型的帖子,我们用border-bottom: none覆盖它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多