要记住的是inline style 将应用于定义它的标签的元素。要影响输入,您需要直接定位它们(演示:1),方法是向它们添加 class,定位所有输入(演示:2),或者如 jthompson 建议的那样,定位那些特定的后代的输入div(请参阅 jthompsons 的回答)。
- `输入{padding-right: 15px; }`,或
- `input[type="radio"] {padding-right: 15px; }` // 我认为这只是 CSS3。
- 添加 `class="q1-radio-inputs"` 并使用 CSS `.q1-radio-inputs {padding-right: 15px; }`
还值得注意的是,使用内联样式并没有多大意义,除非它只需要一次覆盖特定样式,否则(据我所知)使用外部工作表总是更明智,以便用于缓存(如果没有别的),并在重新设计/改造网站时更容易影响所有样式。
并且,作为附录,样式按以下顺序应用:
inline-stlyes 覆盖标题中定义的样式,而标题又覆盖外部样式表。除非使用 !important 标记定义样式,在这种情况下它不会被覆盖(一切正常)。
以下(某种)帮助:http://www.w3.org/TR/CSS2/cascade.html
根据 cmets 编辑:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css" media="screen">
.div#options input { padding-right: 15px }
</style>
</head>
<body>
<div id="question" style="padding-bottom: 15px">
What day is it today?
<div id="options">
<input type="radio" name="question1" />Sunday
<input type="radio" name="question1" />Monday
<input type="radio" name="question1" />Saturday
<input type="radio" name="question1" />Tuesday
</div>
</div>
<div id="question" >
What month is it?
<div id="options">
<input type="radio" name="question1" />Jan
<input type="radio" name="question1" />Feb
<input type="radio" name="question1" />May
<input type="radio" name="question1" />Dec
</div>
</div>
</html>
如果上面的 html 仍然代表您的网站(在 cmets 中链接到这个答案),那么问题很可能是:
.div#options
句点用于表示class名称,井号“#”用于表示div名称,一次只能使用其中一个:
div.options /* is fine, indicating a 'div' of class-name 'options' */
div#options /* is also fine (and both within the same document is, also, fine) indicating a div of id-name 'options' - an id is unique, and can be used only *once* per document */
.div#options /* could be fine, but appears to be targeting an element of id-name 'options' within an element of class-name 'div,' which is not found within your document. */