繁体   English   中英

CSS:如何使用封闭的div覆盖类样式

[英]CSS: How to override a class style with an enclosing div

我有一个无法更改的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>

您可以像我在此处那样为包装div设置一个类: http : //jsfiddle.net/3Zvrg/

HTML:

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

CSS:

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

编辑:基于OP的最新评论

我知道您不能更改课程,但为什么不能这样做。

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

而不将您的“ p”与任何班级联系在一起??

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

您必须在段落元素上显式设置字体大小。

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

div .para1 {
    font-size: 300%;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM