2

我有一个 P 元素,其样式无法更改。我想用 DIV 将其括起来以强制使用新的字体大小。为什么内部 P 忽略了 div 字体大小?

例子:

<html>
<head>
    <style>
        .para1 { font-size:small; }
    </style>
</head>

<div style="font-size:300% !important">
    <p class="para1">I must have been asleep, for certainly if I had been fully awake I must have noticed the approach to such a remarkable place. In the gloom the courtyard looked of considerable size, and as several dark ways led from it under great round arches it perhaps seemed bigger than it really is. I have not yet been able to see it by daylight.</p>
</div>

</html>
4

3 回答 3

4

您可以为包装 div 设置一个类,就像我在这里所做的那样:http: //jsfiddle.net/3Zvrg/

HTML:

<div class="out_of_para1">
    <p class="para1">

CSS:

.out_of_para1 p {font-size: 300%;}

编辑:基于 OP 的最后评论

于 2013-02-04T14:56:57.517 回答
1

我知道你不能改变班级,但你为什么不能这样做。

<div style="font-size:300% !important">
<p>I must have been asleep</p>
</div>

并且不将您的“p”与任何课程相关联?

于 2013-02-04T14:55:24.217 回答
0

只有当属性的值为 时,样式才会被继承inherit。在该段落中,该属性的值为small。因此div的字体大小是300%,但段落的字体大小是small.

您必须明确设置段落元素的字体大小。

您可以使用样式表中的后代选择器来执行此操作:

div .para1 {
    font-size: 300%;
}
于 2013-02-04T14:54:02.800 回答