在CSS中为div使用多个ID

时间:2022-10-13 20:28:49

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

我在网站上有3个DIV元素和这个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.

它似乎只是在#box-right元素上工作。

Any ideas?

3 个解决方案

#1


27  

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;
}

#2


1  

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:

你没有把元素放到你的选择器上,如果你不得不连接一个div或者一个类考虑创建一个新的段落以便很好地理解你的代码,那么你应该很好地理解你的css:

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

#3


1  

Try

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

because it is for all div's anchor tag.

因为它适用于所有div的锚标记。

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

最好给一个锚标记类并直接应用该类。

#1


27  

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;
}

#2


1  

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:

你没有把元素放到你的选择器上,如果你不得不连接一个div或者一个类考虑创建一个新的段落以便很好地理解你的代码,那么你应该很好地理解你的css:

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

#3


1  

Try

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

because it is for all div's anchor tag.

因为它适用于所有div的锚标记。

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

最好给一个锚标记类并直接应用该类。