CSS '&.' 是什么意思 在 '&.sub-title' 中表示在 scss 中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9988558/
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
What does '&.' in '&.sub-title' indicates in scss?
提问by nkm
I am a newbie to CSS and SCSS.
我是 CSS 和 SCSS 的新手。
In the following code,
在以下代码中,
.title {
width: 718px;
&.sub-title {
width: 938px;
}
}
What does &.means? Is it same as nesting class?
& 有什么作用?方法?它与嵌套类相同吗?
回答by Benjie
The &
concatenates the parent class, resulting in .title.sub-title
(rather than .title .sub-title
if the &
is omitted).
The&
连接父类,导致.title.sub-title
(而不是.title .sub-title
如果&
省略)。
The result is that with the &
it matches an element with both title
and sub-title
classes:
结果是&
它匹配了一个同时具有title
和sub-title
类的元素:
<div class='title sub-title'></div> <!-- << match -->
whilst without the &
it would match a descendent with class sub-title
of an element with class title
:
如果没有&
它,它将匹配一个具有 classsub-title
元素的类的后代title
:
<div class='title'>
...
<div class='sub-title'></div> <!-- << match -->
...
</div>