Jonas Byström Jonas Byström - 8 months ago 26
CSS Question

Selecting descendant based on classes

Element type descendant selection works:

form * div {...}

but I find that using classes does not:

.my-class1 * .my-class2

In my page I have two very similar DOM sub-structures generated by third party code that needs different styling, and I don't want my CSS to relying on that third party DOM structure. What is the best way to style these two parts of the DOM?


You can use .my-class1 > .my-class2 to direct descendants.

Or you can use .my-class1 .my-class2 for any .my-class2 that is descendant of .my-class1.