Jonas Byström Jonas Byström - 1 year ago 89
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download