为多个 id 声明相同的 css?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5546183/
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-30 00:08:12 来源:igfitidea点击:
Declaring same css for more than one id?
提问by Basic
How do I do it.
我该怎么做。
#foo, #ball, #tree h1 {color: #892828;}
Does not seem to work?
似乎不起作用?
回答by manji
if you want to style all H1 under those Ids, you have to repeat H1 for every one as they don't share anything:
如果您想在这些 Id 下设置所有 H1 的样式,则必须为每个 Id 重复 H1,因为它们不共享任何内容:
#foo h1, #ball h1, #tree h1 {color: #892828;}
what you wrote is equivalent to:
你写的相当于:
#foo {color: #892828;}
#ball {color: #892828;}
#tree h1 {color: #892828;}
回答by Phillip Musumba
You could also assign the same class to each of those h1s and style using that class.
您还可以使用该类为每个 h1 和样式分配相同的类。