【问题标题】:first-child doesn't work in tbody? [duplicate]第一个孩子在身体中不起作用? [复制]
【发布时间】:2018-07-22 20:58:56
【问题描述】:

我正在尝试在我的 tbody 中选择第一个 td.is-active。 .is-active 样式已被广泛接受,但不可能为第一个(也是唯一一个).is-active 添加半径。

Full code here.

或者只是我的 SCSS:

td {
      &.is-active {
            background-color: $color5;

            &:first-child {
                border-bottom-left-radius: 10px;
                border-top-left-radius: 10px;
        }
       }
}

一个想法?谢谢。

【问题讨论】:

  • 寻求调试帮助的问题(“为什么这段代码不起作用?”)必须在问题本身中包含所需的行为、特定问题或错误以及重现它所需的最短代码 .

标签: css sass css-selectors


【解决方案1】:

CSS 属性不是累积的,不支持子选择。 td.is-active:first-child不会选择.is-active 组中的第一个元素。如果它有.is-active 类,它将选择第一个td,并且没有td 符合这个条件。

td:first-child 将始终选择第一个 td,无论其类别如何。

您正在寻找:first-of-class selector,不幸的是,它不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 2014-10-09
    • 2023-04-02
    • 2011-08-16
    • 2012-08-16
    相关资源
    最近更新 更多