How do I select an element that has a certain class?

The Solution to How do I select an element that has a certain class? is


It should be this way:

h2.myClass looks for h2 with class myClass. But you actually want to apply style for h2 inside .myClass so you can use descendant selector .myClass h2.

h2 {
    color: red;
}

.myClass {
    color: green;
}

.myClass h2 {
    color: blue;
}

Demo

This ref will give you some basic idea about the selectors and have a look at descendant selectors

~ Answered on 2013-06-05 18:08:00


Most Viewed Questions: