2013-03-07 25 views
0

我有问题,使得继承颜色和大小当链接h1和span标签内部的风格。他们应该表现在同样的方式,如果他们在里面TD的。我已经把在链接名称所需的输出。有条件继承的字体,大小和颜色

JS小提琴:

http://jsfiddle.net/lasseedsvik/ym7M7/9/

风格

* { 
    color: #000;  
    font-family: Times; 
    font-size: 14px; 
} 

a { 
    color: red; 
} 

h1 
{ 
    font-family: arial, helvetica; 
    font-size: 27px; 
    color: green; 
} 

的Html

<div id="container"> 
    Default text color 
    <br /> 
    <br /> 
    <a href="#">Red link . default font</a> 
    <br /> 
    <h1><a href="#">Green link - Arial 27px</a></h1> 
    <br /> 
    <span style="font-size: 18px"><a href="#">Red link - 18px default font</a></span> 
</div> 
+0

'H1一个{字体大小:继承;颜色:继承; }'? – BoltClock 2013-03-07 12:52:51

回答

1

尝试

h1 a, span a{ 
    font-size:inherit; 
    font-family:inherit; 
    color:inherit; 
} 
1

使用CSS inherit关键字:

h1 a, 
span a { 
    color: inherit; 
    font: inherit; 
} 

Demo up here

1

可以使用inherit关键字请求继承,但它不是由IE 7支持您可以通过显式声明自己想要什么,例如获得更好的浏览器覆盖面

h1, h1 a 
{ 
    font-family: arial, helvetica; 
    font-size: 27px; 
    color: green; 
} 

上设置两个h1直接内容和包含在任何h1元件a属性。

相关问题