【问题标题】:Not selector does not behave like it should非选择器的行为不像它应该的那样
【发布时间】:2021-08-25 14:49:20
【问题描述】:

这是我的 HTML 代码

<div class="col-1-of-2">
            <h3 class="heading-tertiary u-margin-bottom-small">
              You're going to fall in love with nature
            </h3>
            <p class="paragraph">
              Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
            </p>
            <h3 class="heading-tertiary u-margin-bottom-small">
              Live adventure like you never have before
            </h3>
            <p class="paragraph">
              Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
            </p>
            <a href="#" class="btn-text">Learn More &rarr;</a>
          </div>

现在我在这样的段落类上应用 CSS 样式

.paragraph{
  font-size: 1.6rem;
  &:not(:last-child)
  {
    margin-bottom: 3rem;
  }
}

但它仍然对最后一段应用边距底部看看这里

我做错什么了吗,请指导我正确的方向 谢谢

【问题讨论】:

  • 但是你的最后一个孩子是&lt;a class="btn-text"&gt; 所以它正确地应用了css
  • 你能解决我的疑问吗请我将这个应用于 .paragraph 类,所以它不只选择段落最后一个孩子吗?
  • 你能指导我如何只申请最后一段吗?
  • 好的,知道了!我必须使用最后一个类型。感谢您指出这一点

标签: css sass


【解决方案1】:

如果没有 JS,您无法定位列表中类名的最后一个实例。您只能定位最后一个标签

p:not(:last-of-type) {
    margin-bottom: 3rem;
}

阅读How do I select the "last child" with a specific class name in CSS?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-17
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    相关资源
    最近更新 更多