什么是'&'。在'& .sub-title'中用scss表示? [英] What does '&.' in '&.sub-title' indicates in scss?
问题描述
是CSS和SCSS的新手,所以请原谅我,如果它的一个非常基本的问题。我在网上搜索答案,但我找不到有用的结果。
am a newbie to CSS and SCSS, so please excuse me if its a very basic question. I searched around the web for the answer, but I could not find a helpful result.
在以下代码中,
.title {
width: 718px;
&.sub-title {
width: 938px;
}
}
&。意味着? c>& c>将连接类与嵌套类相同
What does &. means? Is it same as nesting class?
推荐答案
父类,导致 .title.sub-title
(而不是 .title .sub-title
c $ c>& 省略)。
The &
concatenates the parent class, resulting in .title.sub-title
(rather than .title .sub-title
if the &
is omitted).
结果是使用&
它匹配一个具有 title
和子标题
类:
The result is that with the &
it matches an element with both title
and sub-title
classes:
<div class='title sub-title'></div> <!-- << match -->
,而没有&
具有 title
的元素的子标题
的后代:
whilst without the &
it would match a descendent with class sub-title
of an element with class title
:
<div class='title'>
...
<div class='sub-title'></div> <!-- << match -->
...
</div>
这篇关于什么是'&'。在'& .sub-title'中用scss表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!