2013-03-07 66 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屬性。

相關問題