1

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.

Alfie W
  • 21
  • 2

2 Answers2

3

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.

NickCoder
  • 1,448
  • 2
  • 18
  • 31
-1

use a selector list

input#input_9_2, input#input_9_3 {
  max-width: 500px;
}
Yaelet
  • 150
  • 10