@extend rule is helpful in inheriting styles from another selector.
Just like this:
SassScript is pretty handy when it comes to inherit the styles from one selector to another. If the same style applied to another element or selector even without a single rule change, you can just extend the rule. You’d want to do that in a case where you want to manage both selectors style parallely and one of them might get a slight style change in future. There are multiple ways to do that but this involves less coding.
As you can see in the example above, all we need to do is @extend [selector’s name].
This is how it compiles into CSS:
.error, .error--serious {
color: red;
}
.error--serious {
color: red;
font-weight: bold;
font-size: 20px;
}
The elements are styled EXACTLY like they matched the extended selector.
That means if you extend an hover selectors style, it will be used for the hovered state style for that element too. Just like this:
Extend rules are resolved after the stylesheet is compiled completely.
examples extend rules sass