Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use multiple IDs for divs in CSS

Tags:

css

I have 3 DIV Elements on a website and this CSS:

#box-left, #box-middle, #box-right a {
    text-decoration:none;
    color:#000000;
}

it only seems to be working on the #box-right element though.

Any ideas?

like image 837
charlie Avatar asked Aug 02 '13 08:08

charlie


People also ask

Can one div have multiple IDs?

The HTML id attribute is used to specify a unique id for an HTML element. You cannot have more than one element with the same id in an HTML document.

How can I add two IDs in one div?

The second id or any other id after the first one will just be ignored by the browser. So having multiple ids for a div is not only pointless but is also incorrect HTML. If you need multiple tags for an HTML element, just use the class attribute. You can have as many classes as you want.

Can IDs be used multiple times CSS?

The major difference is that IDs can only be applied once per page, while classes can be used as many times on a page as needed. “ if you want to apply same css to multiple html elements, use class. just define a class in css, write all stylings and then give that class to all elements you want to style same.


3 Answers

You have to put

#box-left a, #box-middle a, #box-right a {
    text-decoration:none;
    color:#000000;
}

Each value on the comma separator list is a selector on its own, it is not combined with the next elements:

#foo, .class p, #bar p:first-child a {
  something;
}

is equivalent to

#foo {
  something;
}

.class p {
  something;
}

#bar p:first-child a {
  something;
}
like image 193
Carlos Campderrós Avatar answered Sep 30 '22 04:09

Carlos Campderrós


Try

#box-left a, 
#box-middle a, 
#box-right a {
  text-decoration:none;
  color:#000000;
}

because it is for all div's anchor tag.

It is better to give a anchor tag class and apply that class directly.

like image 40
Bindiya Patoliya Avatar answered Sep 30 '22 06:09

Bindiya Patoliya


You haven't put the element a to your selector, to understand well your css if you have to conatenate more than a div or a class consider to make a new paragraph to understand well your code like this:

#box-left a, 
#box-middle a, 
#box-right a {
    text-decoration:none;
    color:#000000;
}
like image 43
Alessandro Minoccheri Avatar answered Sep 30 '22 05:09

Alessandro Minoccheri