Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'%' in SASS, what does it mean

Tags:

sass

I saw this code, when i was checking Drupal Omega 4 theme

 %container {   @include container;   @include grid-background; } 

what does the '%container' mean? what is the '%' for?

like image 540
Ideal Designs Avatar asked Jun 22 '13 14:06

Ideal Designs


People also ask

What does #{} mean in SCSS?

#{$name} is to output a variable name in escaped format.

What Is percent in Sass?

Percentages in Sass work just like every other unit. They are not interchangeable with decimals, because in CSS decimals and percentages mean different things. For example, 50% is a number with % as its unit, and Sass considers it different than the number 0.5 .

Which symbol represents Placehoder in Sass?

SASS supports placeholder selector using class or id selector. In normal CSS, these are specified with "#" or ".", but in SASS they are replaced with "%".

What are number operations in Sass?

SASS allows for mathematical operations such as addition, subtraction, multiplication and division. You cannot use incompatible units such as px * px or while adding number with px and em leads to produce invalid CSS. Therefore, SASS will display an error if you use invalid units in CSS.


2 Answers

http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#placeholder_selectors_foo

Placeholder Selectors: %foo

Sass supports a special type of selector called a “placeholder selector”. These look like class and id selectors, except the # or . is replaced by %. They’re meant to be used with the @extend directive; for more information see @extend-Only Selectors.

On their own, without any use of @extend, rulesets that use placeholder selectors will not be rendered to CSS.

Example

SCSS SYNTAX

%toolbelt {   box-sizing: border-box;   border-top: 1px rgba(#000, .12) solid;   padding: 16px 0;   width: 100%;    &:hover { border: 2px rgba(#000, .5) solid; } }  .action-buttons {   @extend %toolbelt;   color: #4285f4; }  .reset-buttons {   @extend %toolbelt;   color: #cddc39; } 

CSS Output

.action-buttons, .reset-buttons {   box-sizing: border-box;   border-top: 1px rgba(0, 0, 0, 0.12) solid;   padding: 16px 0;   width: 100%; } .action-buttons:hover, .reset-buttons:hover {   border: 2px rgba(0, 0, 0, 0.5) solid; }  .action-buttons {   color: #4285f4; }  .reset-buttons {   color: #cddc39; } 
like image 127
Popnoodles Avatar answered Oct 02 '22 18:10

Popnoodles


SASS

%icon {   transition: background-color ease .2s;   margin: 0 .5em; }  .error-icon {   @extend %icon;   /* error specific styles... */ }  .info-icon {   @extend %icon;   /* info specific styles... */ } 

Output

.error-icon, .info-icon {   transition: background-color ease .2s;   margin: 0 .5em; }  .error-icon {   /* error specific styles... */ }  .info-icon {   /* info specific styles... */ } 

Note

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.

More info

http://thesassway.com/intermediate/understanding-placeholder-selectors

Tools

If you want to play around Sass please use - http://sassmeister.com/

like image 33
Pravin W Avatar answered Oct 02 '22 17:10

Pravin W