Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge several classes in one?

Tags:

css

sass

I have several classes provided by the Quasar framework. When having several components which are supposed to look the same, I have a repetitive pattern such as

<div class="q-ma-xs text-h6 bg-black">one</div>
<div class="q-ma-xs text-h6 bg-black">two</div>
<div class="q-ma-xs text-h6 bg-black">three</div>
(...)

I am looking for a way to combine all the classes in one, so that a global modification is applied to all elements.

I was hoping that it is possible to use several @extend entries in one new class definition but it does not seem to be the case.

Is there a CSS/SCSS/SASS way to do such a merge?

My backup plan is to use <div :class="myElement">one</div> where myElement is defined in the scripts section (reactivity in Vue) but I would prefer a more native solution.

like image 361
WoJ Avatar asked Oct 22 '25 02:10

WoJ


1 Answers

You can have multiple values in @extend

.myNewClass {
   @extend .q-ma-xs, .text-h6, .bg-black;
}

But I would be really careful with that. @extend does some strange stuff with selector hierarchy.

A better solution might be to create mixins for each of the classes and @include the mixins.

like image 171
Bryce Howitson Avatar answered Oct 24 '25 17:10

Bryce Howitson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!