在 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
来删除不需要的伪选择器?
最佳答案
您可以placeholder selector(%)
将共享属性声明为 #foo
和 #bar
使用如下:
%shared {
position: relative;
}
#foo{
@extend %shared;
&:before {
width: 200px;
content:'';
}
}
#bar {
@extend %shared;
}
关于css - 如何删除SCSS中的伪选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53424689/