I have this in my SCSS file:
.class-a{
display: inline-block;
//some other properties
&:hover{
color: darken(#FFFFFF, 10%);
}
}
.class-b{
//Inherite class-a here
//some properties
}
In class-b, I would like to inherite all properties and nested declarations of class-a
. How is this done? I tried using @include class-a
, but that just throws an error when compiling.
Another option could be using an Attribute Selector:
Whereas every class starting with "your-class-name" uses this style.
So in your case, you could do it like so:
More about Attribute Selectors on w3Schools
Looks like
@mixin
and@include
are not needed for a simple case like this.One can just do:
Using @extend is a fine solution, but be aware that the compiled css will break up the class definition. Any classes that extends the same placeholder will be grouped together and the rules that aren't extended in the class will be in a separate definition. If several classes become extended, it can become unruly to look up a selector in the compiled css or the dev tools. Whereas a mixin will duplicate the mixin code and add any additional styles.
You can see the difference between @extend and @mixin in this sassmeister
Try this:
Now you can extend %base-class in any of your classes (e.g. .my-class).