CSS:为 div 内的输入元素定义样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3304604/
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
CSS:Defining Styles for input elements inside a div
提问by Shyju
I have a div called "divContainer" inside which i have few input elements like textboxes,radio buttons et.. How can i define the style for then in the CSS ? I wanna mention styles for elements inside this purticular div.not for the entire form.
我有一个名为“divContainer”的 div,其中我几乎没有输入元素,如文本框、单选按钮等。我如何在 CSS 中定义样式?我想提到这个 purticular div 中元素的样式,而不是整个表单。
Ex: For textboxes i need width as 150px; For Radio buttons i need width of 20px;
例如:对于文本框,我需要宽度为 150px;对于单选按钮,我需要 20px 的宽度;
回答by David Underhill
You can define style rules which only apply to specific elements inside your div
with id divContainer
like this:
您可以定义仅适用于您的div
with id 中的特定元素的样式规则,divContainer
如下所示:
#divContainer input { ... }
#divContainer input[type="radio"] { ... }
#divContainer input[type="text"] { ... }
/* etc */
回答by μBio
CSS 3
CSS 3
divContainer input[type="text"] {
width:150px;
}
CSS2 add a class "text" to the text inputs then in your css
CSS2 添加一个类“文本”到文本输入然后在你的 css 中
.divContainer.text{
width:150px;
}
回答by Kerry Jones
When you say "called" I'm going to assume you mean an ID tag.
当你说“被叫”时,我假设你的意思是一个 ID 标签。
To make it cross-brower, I wouldn't suggest using the CSS3 []
, although it is an option. This being said, give each of your textboxes a class like "tb" and the radio button "rb".
为了使其跨浏览器,我不建议使用 CSS3 []
,尽管它是一个选项。话虽如此,给你的每个文本框一个类,比如“tb”和单选按钮“rb”。
Then:
然后:
#divContainer .tb { width: 150px }
#divContainer .rb { width: 20px }
This assumes you are using the same classes elsewhere, if not, this will suffice:
这假设您在其他地方使用相同的类,如果没有,这就足够了:
.tb { width: 150px }
.rb { width: 20px }
As @David mentioned, to access anything within the division itself:
正如@David 提到的,要访问部门内部的任何内容:
#divContainer [element] { ... }
Where [element] is whatever HTML element you need.
其中 [element] 是您需要的任何 HTML 元素。
回答by Dagg Nabbit
Like this.
像这样。
.divContainer input[type="text"] {
width:150px;
}
.divContainer input[type="radio"] {
width:20px;
}