【问题标题】:How to remove pseudo selector in SCSS?如何删除 SCSS 中的伪选择器?
【发布时间】:2019-04-24 18:25:22
【问题描述】:

在 SCSS 中,我使用 @extend 将 2 个选择器合并到 1 行中,但伪选择器 (:before) 是在 #bar 内部创建的,如下所示:

#foo {
  position: relative;
  &:before {
    width: 200px;
  }
}
#bar {
  @extend #foo;
}

输出:

#foo, #bar {
  position: relative; 
}
#foo:before, #bar:before {
  width: 200px; 
}

我想用 SCSS 做这样的:

#foo, #bar {
  position: relative; 
}
#foo:before {
  width: 200px; 
}
/* I want to remove #bar:before */

有没有办法通过创建@extend 来删除不需要的伪选择器?

【问题讨论】:

    标签: css sass nested selector extend


    【解决方案1】:

    您可以placeholder selector(%)#foo#bar 声明您的共享属性

    See example

    如下使用:

    %shared {
      position: relative;
    }
    #foo{
       @extend %shared;
        &:before {
        width: 200px;
        content:'';
      }
    }
    #bar {
        @extend %shared;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-01
      • 1970-01-01
      • 2014-09-26
      • 2017-12-18
      • 2018-01-11
      • 1970-01-01
      • 1970-01-01
      • 2016-02-05
      • 1970-01-01
      相关资源
      最近更新 更多