Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SCSS, what does % symbol indicate? [duplicate]

Tags:

css

sass

What does % indicate in scss?

Use of % in context: (source: https://codepen.io/FWeinb/pen/GrpqB?editors=1100)

@import "compass/css3";

.box{
  margin: 5em auto;
  position: relative;
  width: 10em;
  height: 10em;
  line-height: 10em;
  overflow: hidden;
}

%box__dir{
  position: absolute;
  width: inherit;
  height: inherit;          
  text-align: center;
  line-height: inherit;
  transition:transform .4s ease;
}

What does the percentage sign before "box_dir" indicate?

like image 340
xing Zì Avatar asked Mar 16 '19 10:03

xing Zì


People also ask

What is symbol in SCSS?

Sass uses the $ symbol to make something a variable. Here's an example: SCSS. Sass.

What does mean SCSS?

SCSS : Syntactically Awesome Style Sheet is the superset of CSS. SCSS is the more advanced version of CSS. SCSS was designed by Hampton Catlin and was developed by Chris Eppstein and Natalie Weizenbaum. Due to its advanced features it is often termed as Sassy CSS. SCSS have file extension of .

How many syntaxes that sass support?

Sass consists of two syntaxes.


1 Answers

In SCSS, the % indicates a placeholder selector.

[Placeholders] are very similar to class selectors, but instead of using a period (.) at the start, the percent character (%) is used. Placeholder selectors have the additional property that they will not show up in the generated CSS, only the selectors that extend them will be included in the output.

So if you included this in your SCSS somewhere but never used (extended) it, it will not appear in your generated CSS.

%box__dir {
 position:absolute;
 width:inherit;
 height:inherit;
 text-align:center;
 line-height:inherit;
 transition:transform .4s ease;
}

Once you use the placeholder, it will appear in your generated CSS as expected.

.something {
  color: red;
  @extend %box__dir;
}

Generated CSS:

.something {
  color: red;
  position:absolute;
  width:inherit;
  height:inherit;
  text-align:center;
  line-height:inherit;
  transition:transform .4s ease;
}
like image 92
Andy Hoffman Avatar answered Sep 21 '22 20:09

Andy Hoffman