Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '&.' in '&.sub-title' indicates in scss?

Tags:

css

sass

I am a newbie to CSS and SCSS.

In the following code,

.title {
    width: 718px;
    &.sub-title {
      width: 938px;
   }
}

What does &. means? Is it same as nesting class?

like image 291
nkm Avatar asked Apr 03 '12 07:04

nkm


1 Answers

The & concatenates the parent class, resulting in .title.sub-title (rather than .title .sub-title if the & is omitted).

The result is that with the & it matches an element with both title and sub-title classes:

<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:

<div class='title'>
  ...
    <div class='sub-title'></div> <!-- << match -->
  ...
</div>
like image 155
Benjie Avatar answered Sep 23 '22 18:09

Benjie