【问题标题】::first-child but only if element before is not input[type="hidden"]:first-child 但前提是之前的元素不是输入[type="hidden"]
【发布时间】:2021-12-29 19:08:40
【问题描述】:

我有一种情况,我设置了 25px 上边距,然后如果此元素是第一个子元素,我将其删除。

e.q.

.div-name {
margin-top: 25px;

    &:first-child {
        margin-top: 0;
    }
}

但有时我之前有<input type="hidden" />,然后我也想删除上边距,但现在它不是第一个孩子。

如何有条件地使用 &:first-child?

【问题讨论】:

  • :first-child之后尝试:not([type=hidden])

标签: css css-selectors


【解决方案1】:
.div-name {
margin-top: 25px;

    &:first-child:not([type=hidden]) {
        margin-top: 0;
    }
}

【讨论】:

  • 已经累了,不行了……
  • 你能详细解释一下你的问题吗?
  • margin-top: 0 不适用于 .div-name 如果 hidden 是第一个元素
  • 可以加html和css吗
  • 它是一个 React 组件
猜你喜欢
  • 1970-01-01
  • 2013-08-07
  • 2016-06-24
  • 2020-06-15
  • 1970-01-01
  • 1970-01-01
  • 2019-03-25
  • 1970-01-01
  • 2018-03-01
相关资源
最近更新 更多