简体   繁体   English

为多个ID设置CSS类

[英]Set CSS class for several ID

I have done the following: 我已经完成以下工作:

#my-el .some-class {
    width: 10%;
}

That works but now I'd like to apply the same class to the element #my-new-el. 那行得通,但是现在我想将相同的类应用于元素#my-new-el。 I've tried: 我试过了:

#my-el #my-new-el .some-class {
    width: 10%;
}

But this does not work. 但这是行不通的。 What would be the correct syntax to achieve this ? 实现此目的的正确语法是什么?

If .some-class only applies to descendents of #my-el and #my-new-el then you need to specify the two selectors in full, separated by a comma: 如果.some-class仅适用于#my-el#my-new-el后代,则需要完整指定两个选择器,并用逗号分隔:

#my-el .some-class, #my-new-el .some-class  {
    width: 10%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM