Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring same css for more than one id?

Tags:

css

How do I do it.

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

Does not seem to work?

like image 934
Basic Avatar asked Apr 05 '11 01:04

Basic


People also ask

Can CSS have multiple ID?

You cannot have multiple IDs for a single div tag. There is never any need for multiple ids on the same tag since ids are unique either one would serve to uniquely identify that specific tag provided you first get rid of the other id which is stopping things working.

How many IDs can you have in CSS?

CSS IDS. An ID is a singular identifier of one HTML tag. You can only have one HTML tag per ID and each HTML tag can only have one ID. Each ID has a specific set of CSS attributes that only apply to that one element.

Can you use the same CSS class on multiple elements?

Multiple classes can be applied to a single element in HTML and they can be styled using CSS.

How can we apply same styles to multiple selectors?

When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your stylesheet. Instead of having two, three, or more CSS rules that do the same thing (set the color of something to red, for example), you use a single CSS rule that accomplishes the same thing.


1 Answers

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;} 
like image 96
manji Avatar answered Oct 11 '22 14:10

manji