什么是'&'。在'& .sub-title'中用scss表示? [英] What does '&.' in '&.sub-title' indicates in scss?

查看:149
本文介绍了什么是'&'。在'& .sub-title'中用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>

这篇关于什么是'&amp;'。在'&amp; .sub-title'中用scss表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆