CSS Sass 中的多个二类选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18561547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:13:10 来源:igfitidea点击:
Multiple two-class selectors in Sass
提问by Fellow Stranger
Having multiple two-class selectors for a single declaration block, is it possible to simplify the following (i.e. not having to repeat the body
tag):
对于单个声明块有多个二类选择器,是否可以简化以下内容(即不必重复body
标记):
body.shop, body.contact, body.about, body.faq {background-color:#fff;}
回答by Alessandro Minoccheri
try this:
尝试这个:
body{
&.shop, &.contact, &.about, &.faq {
background-color:#fff;
}
}
回答by Dmitry
In this case we can use @each
directive:
在这种情况下,我们可以使用@each
指令:
$pages: shop, contact, about, faq;
body {
@each $page in $pages {
&.#{$page} {
background-color:#FFF;
}
}
}
回答by Joseph Silber
body {
&.shop, &.contact {
// Styles here...
}
}