Inheriting and overriding styles with extend

Up until now, we've used mixins to help reduce the need to write extra code, as we can call these blocks of code from our Less statements easily, to produce the desired effect.

Unfortunately this is still not without its own drawback. Let's say we create two rules, that both call the same mixin, and produce identical results (save for the rule name), then Less will interpret these as two separate blocks of code, even though they both perform the same styling on two different objects. What if we could merge these two rules together so that there is only one block of code, but which can be called by either rule?

Well, we can, with the use of the extend function in Less. This is a really powerful function, ...

Get Learning Less.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.