问题
I can't combine these selectors into a single CSS rule. I'm trying to edit the width of certain form fields.
input#input_9_2 {
max-width: 500px;
}
input#input_9_3 {
max-width: 500px;
}
When I try to combine them, the rule does not apply to either. But they work when written separately, as above.
回答1:
To group CSS selectors in a style sheet, you use commas to separate multiple grouped selectors in the style. In this example, the style affects two classes input#input_9_2 and input#input_9_3.
input#input_9_2,
input#input_9_3
{
max-width: 500px;
}
The comma means "and", so this selector applies to all input#input_9_2 elements and input#input_9_3 elements. If the comma were missing, the selector would instead apply to all input#input_9_3 elements that are a child of an input#input_9_2. That is a different kind of selector, so the comma is important.
Any form of the selector can be grouped with any other selector.
回答2:
use a selector list
input#input_9_2, input#input_9_3 {
max-width: 500px;
}
来源:https://stackoverflow.com/questions/57035939/how-to-combine-multiple-selectors-for-the-same-rule