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

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

我使用了这个代码:

input, textarea {
background-color: #d1d1d1;
}
516420 次浏览
input[type="text"], textarea {


background-color : #d1d1d1;


}

Hope that helps :)

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

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)).

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

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.

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; }