Sometimes you’ll write styles for a class that you only ever want to @extend
, and never want to use directly in your HTML. This is especially true when writing a Sass library, where you may provide styles for users to @extend
if they need and ignore if they don’t.
If you use normal classes for this, you end up creating a lot of extra CSS when the stylesheets are generated, and run the risk of colliding with other classes that are being used in the HTML. That’s why Sass supports “placeholder selectors” (for example, %foo
).
Placeholder selectors look like class and id selectors, except the #
or .
is replaced by %
. They can be used anywhere a class or id could, and on their own they prevent rulesets from being rendered to CSS.
selector_inheritance_w_silent_extend.scss
For more information and examples as to how the @extend
directive works, be sure to read Sass Extends: be aware of the loop.