Suppose I have a en element <div clas="foo bar foobar">[stuff]</div>
and I want to replace these three classes with one class (SuperFoo).
While I could find out how foo, bar and foobar are defined, and use each of those elements:
.SuperFoo { color : red }
and so on, is it possible to define SuperFoo in terms of foo, bar and foobar?
.SuperFoo { foo bar foobar}
?
How can I do this?
To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element.
CSS grouping can be used to condense code that has multiple selectors with the same declarations. This makes code easy to read and maintain. Also development time is significantly reduced as there is less code to write. Page load times are reduced as well when using grouping.
We aren't limited to only two here, we can combine as many classes and IDs into a single selector as we want.
Unless you use LESS or SASS's 'mixin' features, there's no real way in plain CSS to "inherit" other classes.
The best you can do is apply all three classes to your DOM element.
If your problem is that you have a ton of those classes already on a page and you want to add properties to all of them, you can do:
.foo, .bar, .foobar {
color: red;
}
and that will apply color: red to any element that has .foo or .bar or .foobar.
No. But you could use chained classes:
.foo.bar.foobar {
color: red;
}
<div class="foo bar foobar">[red]</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With