如何使用 <select> CSS 按名称定位表单元素?



我有3个表单元素

<select name="closing_date[]"></select>

这些是生成的,所以不能添加类或id,我的css什么也不做

select[name=closing_date] {
  width: 33% !important;
  background: red;
}

Demo

试题:

select[name^=closing_date] {
  width: 33% !important;
  background: red;
}

查看MDN关于属性选择器的文章

[attr ^ =价值]

表示属性名为attr和的元素

应该是

select[name="closing_date[]"] {
    width: 33% !important;
    background: red;
}

演示。

这也是工作:

html

<select name="closing_date[]"></select>
<select name="closing_date[]"></select>
<select name="closing_date[]"></select>
css

select[name='closing_date[]'] {
  width: 33% !important;
  background: red;
}

最新更新