Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS:using single rule for multiple Ids

I was using a generic rule for TH tag of Table but it disturbed every thing. I was using the rule as:

th
{
    color: #fff;
    background: #7d7e7d;
}

But now I want to specify Ids for a few tables so that it does not effect other tables at all. What I did was:

#id1,#id2  th
{
    color: #fff;
    background: #7d7e7d;
}

what it did that color spread in as well. How do I achieve my task?

like image 263
Volatil3 Avatar asked May 19 '12 12:05

Volatil3


People also ask

Can you have multiple IDs in CSS?

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.

Can I select multiple elements at once with CSS?

It is possible to give several items on your page the same style even when they don't have the same class name. To do this you simply list all of the elements you want to style and put a comma between each one.

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.

Can a style rule have multiple selectors?

Yes. It still will receive the style specified by the last selector in order from top to bottom that refers to the html element specified. The order in which the class names appear in the element tag itself will make no difference.


1 Answers

You need to specify th both times as the comma separates entire selectors:

#id1 th, #id2 th
{
    color: #fff;
    background: #7d7e7d;
}

Otherwise you're selecting the entire #id1 as well as just #id2 th.

like image 168
BoltClock Avatar answered Sep 29 '22 04:09

BoltClock