【发布时间】:2013-05-27 20:38:22
【问题描述】:
使用以下 CSS:
* {
margin: 0;
padding: 0;
font-family:"Segoe UI";
font-variant: small-caps;
}
.red {
color: hsl(0, 100%, 50%);
font-size: 3em;
}
.orange {
color: hsl(30, 100%, 50%);
font-size: 3em;
}
.yellow {
color: hsl(60, 100%, 50%);
font-size: 3em;
}
.green {
color: hsl(120, 100%, 50%);
font-size: 3em;
}
.blue {
color: hsl(210, 100%, 50%);
font-size: 3em;
}
.indigo {
color: hsl(230, 100%, 50%);
font-size: 3em;
}
.violet {
color: hsl(274, 100%, 50%);
font-size: 3em;
}
... * 选择器中的属性工作正常 - 它们适用于所有类;但是,如果我将 font-size 移动到那里,文本就会变成暴龙的比例。您可以通过将字体大小从各个类移动到 * 类来看到这一点:http://jsfiddle.net/NvTvr/8/
为什么会这样?
更新
所以这是要走的路,那么:
* {
margin: 0;
padding: 0;
font-family:"Segoe UI";
font-variant: small-caps;
font-size: 48px;
}
.red {
color: hsl(0, 100%, 50%);
}
...等等。 (在颜色类中没有指定字体大小);如http://jsfiddle.net/NvTvr/10/中所见@
【问题讨论】:
-
您不必对
*应用任何字体样式。虽然不像font-size那样有问题,但您仍然不必要地将它们应用于已接受答案中提到的所有元素。 -
请不要编辑问题以包含答案。编辑问题只是为了澄清您的问题。
-
@BoltClock:通过 * 选择器将边距和填充重置为 0 不是公认的做法吗?