SASS has a feature called @extend
which allows a selector to inherit the properties of another selector, but without copying the properties (like mixins).
Does LESS have this feature as well?
SASS has a feature called @extend
which allows a selector to inherit the properties of another selector, but without copying the properties (like mixins).
Does LESS have this feature as well?
Yes, Less.js introduced
extend
in v1.4.0.Rather than implementing the at-rule (
@extend
) syntax used by SASS and Stylus, LESS implemented the pseudo-class syntax, which gives LESS's implementation the flexibility to be applied either directly to a selector itself, or inside a statement. So both of these will work:or
Additionally, you can use the
all
directive to extend "nested" classes as well:And you can add a comma-separated list of classes you wish to extend:
When extending nested selectors you should notice the differences:
nested selectors
.selector1
andselector2
:Now
.selector3:extend(.selector1 .selector2){};
outputs:,
.selector3:extend(.selector1 all){};
outputs:,
.selector3:extend(.selector2){};
outputsand finally
.selector3:extend(.selector2 all){};
:Easy way to extend a function in Less framework
Refer https://codepen.io/sprushika/pen/MVZoGB/