user1175969 user1175969 - 4 months ago 7
CSS Question

Combine multiple existing classes into a single class

I currently have a lot of buttons in various views with the following classes applied

class="btn btn-primary btn-sm custom"
. How do I include
"btn btn-primary btn-sm"
within
"custom"
in my CSS so that I can just use the single class rather than specifying each separately?

Answer

LESS supports mixins, but you will have to import the bootstrap.less file first.

For a mixin, the syntax is:

.custom {
    .btn;
    .btn-primary;
    .btn-sm;
}

For info on importing bootstrap.less as just a reference for your mixins, see Reference a class/mixin without completely importing the LESS file

Comments