html 表单中文本输入的边框

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

border around text input in a html form

htmlcss

提问by leofer

I want a red border around my input text fields in a html form. But using css

我想要一个 html 表单中我的输入文本字段周围的红色边框。但是使用css

input { border: 1px solid #d66 }

also puts a red border around my buttons (which I don't want).

还在我的按钮周围放置了一个红色边框(我不想要)。

input.button, input.submit or input.text and anything inside { } doesn't do anything.

input.button、input.submit 或 input.text 以及 { } 中的任何内容都不起作用。

How do I change the border around a text input only, and how do I change the font in the submit button only? I'm using IE9.

如何仅更改文本输入周围的边框,以及如何仅更改提交按钮中的字体?我正在使用 IE9。

Thanks!

谢谢!

回答by giftcv

To target textboxes, use

要定位文本框,请使用

input[type="text"] { border: 1px solid #d66 }

There are a lot more attribute selectors available.

还有更多可用的属性选择器。

Have a look at http://css-tricks.com/attribute-selectors/

看看http://css-tricks.com/attribute-selectors/

回答by Kyle

What you need is an attribute selector:

你需要的是一个属性选择器:

input[type="text"] { border: 1px solid #d66 }

This selects the input of type "text."

这将选择“文本”类型的输入。

You can also use other attribute selectors to select other elements:

您还可以使用其他属性选择器来选择其他元素:

input[type="submit"] { border: 1px solid #d66 }
input[type="checkbox"] { border: 1px solid #d66 }

But also be aware that these selectors are not supported by IE7 and lower.

但也请注意,IE7 及更低版本不支持这些选择器。