Html 表单中的背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6786963/
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
Background color in forms
提问by 3D-kreativ
I'm trying to set a background color to the HTML form tag, but it doesn't work?! I thought it was a simple task!
我正在尝试为 HTML 表单标签设置背景颜色,但它不起作用?!我以为这是一个简单的任务!
#form {
background-color: #000;
padding: 10px;
}
采纳答案by Samuele Mattiuzzo
Can we just see the HTML code of your form? Maybe there's a class you're using that conflicts with your #form declaration.
我们可以看看你的表单的 HTML 代码吗?也许您正在使用的某个类与您的 #form 声明冲突。
Also, if you want the "form block" to have a background, put it inside a div and background it.
此外,如果您希望“表单块”具有背景,请将其放在 div 中并将其作为背景。
If you want to give a background to the form inputs, you should give a style to the input objects
如果你想给表单输入一个背景,你应该给输入对象一个样式
#form input{
background-color: #000;
}
#form input .submit{ ... }
#form label { ... }
And so on.
等等。
回答by user3817445
You can use an inline style:
您可以使用内联样式:
<form style="background-color:#E6E6FA">
<input type="submit" value="ClickMe" >
</form>
回答by Arash Kazemi
You should post the HTML content, but if you want to set the style sheet for the form "tag", you should not use #. instead do something like:
您应该发布 HTML 内容,但如果您想为表单“标签”设置样式表,则不应使用 #。而是做类似的事情:
form {background:#000000;}
"#" is applied for the elements with the appended id, and the style sheet you have written works for an element like < div id="form" >etc...< /div >
“#”适用于带有附加 id 的元素,您编写的样式表适用于像 < div id="form" >etc...</div> 这样的元素
回答by Frank Thuerigen
I had the same problem. The form had fieldset tags in it, and those had the style float:left
. This caused the background-color not to be rendered. Without the float it worked.
我有同样的问题。表单中有 fieldset 标签,这些标签有 style float:left
。这导致不呈现背景颜色。没有浮动它就起作用了。
回答by batman21
If you want no background in your form then set the background to none
:
如果您不希望表单中没有背景,则将背景设置为none
:
<form style="background:none">
回答by Rahul Jai sharma
For background colors in a form, notify the form control in the form tag and provide this form field in the style tag as shown below.
对于表单中的背景颜色,请在表单标签中通知表单控件并在样式标签中提供此表单字段,如下所示。
form {
background-color: #FFC;
}