From the course: CSS: Selectors

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Compound selectors

Compound selectors - CSS Tutorial

From the course: CSS: Selectors

Start my 1-month free trial

Compound selectors

- [Instructor] It's possible to combine selectors in all kinds of interesting ways. We'll cover many of these ways in the course, but the first way I'd like to discuss is what's called a compound selector. So if you take a look here at this code pen, you'll notice over here in our HTML we have both a paragraph and a unordered list that have a class of myclass. They both have red text inside of them in the display down here on the bottom. What if I only wanted to have the paragraph appear red, while the ul appeared blue? So with a CSS class that I have here right now that's not going to be possible because anything with a class of myclass will be red. However, if I go in ahead and put that HTML element in front of the myclass selector, in other words let's just say p.myclass, then only the paragraph will wind up being red in this case. And that is because this selector is saying that for all paragraphs that have that class of myclass do the following things. Likewise, we could say…

Contents