你好,我想在我的css中使用来自浏览器默认值的简单继承:
.myfromh1{
font-weight: bold;
}我能告诉css .myfromh1类拥有h1默认类的所有属性吗?
谢谢阿曼。
发布于 2010-08-09 14:17:46
从你的问题上还不太清楚你想实现什么。CSS使用覆盖规则的层次结构。
内联样式优先于<style>块代码。
<style type="text/css">
#test { color: red; }
</style>
<span id="test" style="color: blue;">This text will be blue</span>所有样式都优先于在代码中前面定义的样式。
<style type="text/css">
#test { color: red; }
#test { color: blue; }
</style>
<span id="test">This text will be blue</span>具有高特异性的样式优先于不太特定的样式。
<style type="text/css">
#test { color: blue; }
.test { color: red; }
</style>
<span id="test" class="test">This text will be blue</span>一些浏览器尊重!important关键字
<style type="text/css">
span { color: blue !important; }
#test { color: red; }
<span id="test">This text should be blue</span>因此,要回答您的问题,如果您的元素是H1元素,那么它将自动拥有h1选择器的所有属性,并且只有被#myfromh1选择器覆盖的属性才会被更改。
但是,如果您在选择器之间寻找真正的继承--如果#myfromh1不是一个H1元素,但是您希望它的样式为一个,那么答案是在CSS中无法实现这一点。
发布于 2010-08-09 14:02:24
h1#myfromh1{
font-weight: bold;
}发布于 2010-08-09 14:03:21
是的,只需将id myfromh1给<h1>-HTML元素即可。
https://stackoverflow.com/questions/3440739
复制相似问题