【问题标题】:reverting @extend in SASS在 SASS 中恢复 @extend
【发布时间】:2023-04-03 21:19:01
【问题描述】:

我想在某些条件下@extend 一个类,在其他条件下撤销该@extend

<div class="myclass">
 <div class="not_special">
</div>
</div>

所以当没有 .not_special 孩子时,它会是

.myclass
  @extend .special

当有一个 .not_special 孩子时

.myclass:has(.not_special)
  //revoke the previous @extend

我不能使用 javascript 添加或删除类,因为事件没有明确定义,因为可能有很多事件并且不可能全部捕获

【问题讨论】:

标签: css sass extend


【解决方案1】:

使用:not伪类

.myclass:not:has(.not_special)
    @extend .special

这会将@extend 应用于所有.myclass,除非他们有一个孩子.not_special

【讨论】:

  • 这将引用 .myclass.not_special,我需要为没有子 .not_special 的 .myclass 设置样式
  • 抱歉 - 我误解了你的更新,所以现在答案应该可以了
猜你喜欢
  • 1970-01-01
  • 2013-03-26
  • 2013-08-03
  • 2021-11-27
  • 2018-01-30
  • 2015-08-25
  • 2015-11-09
  • 2016-01-20
相关资源
最近更新 更多