Html 选择列表的 CSS 样式输入 [type="??"]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9904653/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:22:51  来源:igfitidea点击:

CSS styling input [type="??"] for select lists

htmlcsscss-selectors

提问by Nick

Possible Duplicate:
CSS Select Selector

可能的重复:
CSS 选择选择器

What is the CSS equivalent to the following when dealing with select lists?

处理选择列表时,CSS 等效于以下内容?

input[type="text"]
input[type="submit"]

回答by Matt

The input[type="text"]CSS selector can be broken down into;

input[type="text"]CSS选择器可以被分解成;

  1. input; find all elements that are inputelements.
  2. [type="text"]; filter those elements by those which have the typeattribute of text.
  1. input; 找到所有属于input元素的元素。
  2. [type="text"]; 通过具有type属性的元素过滤这些元素text

Because a select box is a <select>element rather than a <input type="select" />, you can just use the selectselector as follows;

因为选择框是一个<select>元素而不是 a <input type="select" />,所以你可以select像下面这样使用选择器;

select {
    /* blah blah blah*/
} 

回答by Fabrizio Calderan

select is not a type of input like those in your example, so you cannot use an attribute selector when you target a select

select 与您的示例中的输入类型不同,因此当您定位一个时,您不能使用属性选择器 select

回答by patad

select {
   border:1px solid green; 
}

  select option {
     font-weight:bold; 
  }

回答by Stéphane

As Fabrizio-Calderan says, select does not have a type property. however, you could use the data-property and style your element based on this

正如 Fabrizio-Calderan 所说, select 没有 type 属性。但是,您可以使用数据属性并基于此设置元素样式

see here : Select elements by data attribute in CSS

请参见此处:通过 CSS 中的数据属性选择元素

Why not using a class to style it?

为什么不使用一个类来设计它?

Pseudo code:

伪代码:

<select>
    <option class="wise">
    <option class="not-so-wise">
    <option class="meh">
</select>