CSS 输入和文本字段中的背景颜色

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

Background color in input and text fields

css

提问by 3D-kreativ

I would like to change the color background in the text and input fields of a form, but when I do this it also affects the submit button! Could it be done in some other way that does not affect the button?

我想更改表单文本和输入字段中的颜色背景,但是当我这样做时,它也会影响提交按钮!是否可以以不影响按钮的其他方式完成?

I have used this code:

我用过这个代码:

input, textarea {
  background-color: #d1d1d1;
}

回答by Damien-Wright

input[type="text"], textarea {

  background-color : #d1d1d1; 

}

Hope that helps :)

希望有帮助:)

Edit:working example, http://jsfiddle.net/C5WxK/

编辑:工作示例,http : //jsfiddle.net/C5WxK/

回答by kapa

The best solution is the attribute selector in CSS (input[type="text"]) as the others suggested.

最好的解决方案是 CSS ( input[type="text"]) 中的属性选择器,正如其他人建议的那样。

But if you have to support Internet Explorer 6, you cannot use it (QuirksMode). Well, only if you have to and also are willing to support it.

但是如果您必须支持Internet Explorer 6,则不能使用它 ( QuirksMode)。好吧,只有在您必须并且愿意支持它的情况下。

In this case your only option seems to be to define classes on input elements.

在这种情况下,您唯一的选择似乎是在输入元素上定义类。

<input type="text" class="input-box" ... />
<input type="submit" class="button" ... />
...

and target them with a class selector:

并使用类选择器定位它们:

input.input-box, textarea { background: cyan; }

回答by Eric Conner

You want to restrict to input fields that are of type text so use the selector input[type=text]rather than input(which will apply to all input fields (e.g. those of type submit as well)).

您希望限制为文本类型的输入字段,因此请使用选择器input[type=text]而不是input(这将适用于所有输入字段(例如那些类型为 submit 的输入字段))。