Search code examples
htmlcssclasscss-specificity

HTML. Assign multiple classes with subclasses to a element


I'm struggling with HTML classes. I've got these classes in CSS:

.a{}
.a .b{}
.a .c{}

And I'm trying to assign two classes to elements like this:

<div class="a b"></div>
<div class="a c"></div>

But none of these work, the element only inherits "a" class. I think It is logically that the second class must be assigned in absolute way like:

<div class="a (a b)"></div>

But I can't find the correct way. Maybe what I'm trying to do is stupid but I can't find another way (keeping specificity in CSS).


Solution

  • The selector for "has both classes a and b" is .a.b, so no space in between.