我想在 SCSS 中写这样的东西:
.username {
color: red;
@something .mobile {
font-weight: bold
}
@something .desktop {
font-weight: normal
}
}
...在 CSS 中有以下输出:
.mobile .username {
color: red;
font-weight: bold
}
.desktop .username {
color: red;
font-weight: normal;
}
我怎样才能做到这一点?
答案 0 :(得分:5)
在课后使用 parent selector sealed class
,如下所示:
&
这是一个demo
注意:不需要重复.username {
color: red;
.mobile & {
font-weight: bold
}
.desktop & {
font-weight: normal
}
}