css 多个类/ id 选择器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3458169/
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
css multiple class / id selectors?
提问by aeq
I'd like to know how to write a css block that applies to either multiple idsor multiple classes:
我想知道如何编写一个适用于多个id或多个类的 css 块:
Something like:
就像是:
.class1, .class2 {
...
}
or
或者
#id1, #id2 {
...
}
I'd like to know how to do both cases (which hopefully are cross browser compliant). Thanks.
我想知道如何处理这两种情况(希望是跨浏览器兼容的)。谢谢。
Update:To make it more interesting, is this valid too?
更新:为了让它更有趣,这也有效吗?
#id tr, #id2 tr {
}
?
?
回答by Pranay Rana
You are looking for something like this :
你正在寻找这样的东西:
.oddBoxOut,
.evenBoxOut {
width: 12em;
padding: 0.5em;
margin: 0.5em;
border: solid 1px black;
}
.oddBoxOut {
float: left;
}
.evenBoxOut {
float: right;
}
Update :
更新 :
p#exampleID1 { background-color: blue; }
p#exampleID2 { text-transform: uppercase; }
回答by Buhake Sindi
For your updateit is also valid,
对于您的更新,它也有效,
#id1 tr {
}
means that every childof node id #id1will be CSS'ed.
意味着节点 id #id1 的每个子节点都将被 CSS 处理。
you can do this too
你也可以这样做
tr#id1 {
}
Only tr
will be affected if id == #id1
仅tr
当 id == 时才会受到影响#id1