在 CSS 中为 div 使用多个 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18012513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:46:05  来源:igfitidea点击:

Use multiple IDs for divs in CSS

css

提问by charlie

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-rightelement though.

不过,它似乎只对#box-right元素起作用。

Any ideas?

有任何想法吗?

回答by Carlos Campderrós

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

回答by Bindiya Patoliya

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.

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

回答by Alessandro Minoccheri

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:

您还没有将元素 a 放到您的选择器中,以便更好地理解您的 css,如果您必须连接多个 div 或一个类,请考虑创建一个新段落以很好地理解您的代码,如下所示:

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