Basic
Basic

Reputation: 1866

Declaring same css for more than one id?

How do I do it.

#foo, #ball, #tree h1 {color: #892828;}

Does not seem to work?

Upvotes: 40

Views: 66826

Answers (3)

AbgrundLemur
AbgrundLemur

Reputation: 35

:is(#foo, #ball, #tree) h1 {color: #892828;}

This approach works with any ID, no need for prefixing and attribute selectors. The CSS pseudo-class :is() is now supported by all major browsers.

Upvotes: 0

Phillip Musumba
Phillip Musumba

Reputation: 71

You could also assign the same class to each of those h1s and style using that class.

Upvotes: 0

manji
manji

Reputation: 47978

if you want to style all H1 under those Ids, you have to repeat H1 for every one as they don't share anything:

#foo h1, #ball h1, #tree h1 {color: #892828;}

what you wrote is equivalent to:

#foo {color: #892828;}
#ball {color: #892828;}
#tree h1 {color: #892828;}

Upvotes: 71

Related Questions