evantig03
evantig03

Reputation: 13

Can you apply one property in a class for a DIV differently for two elements?

I want to have a DIV whose background color is light grey, but I want the background color for HRs to be black. I'd like to have one class for the DIV that can control both of these so I don't have to apply a separate class for each HR?

Upvotes: 0

Views: 37

Answers (2)

Sweet_Cherry
Sweet_Cherry

Reputation: 333

A class can't control both of them, but it's possible to not have to apply a separate class for each HR.

Upvotes: 0

Lazar Ljubenović
Lazar Ljubenović

Reputation: 19764

What you describe is not possible. However, you might be looking for this:

div hr {
  background-color: black;
}

div hr will match all hr which are descendants of div. This means you do not have to apply a class for each hr element, which is what you requested in the question.

For direct descendants only (children), use div > hr.

Upvotes: 1

Related Questions