課程pptcss
舉例:html
<p> This is a <em>test</em> of <strong>inherit</strong>. </p> <style> p { color: #666; } </style>
上述代碼,em
標籤裏的color
就會繼承父元素的color
,爲color: #666
。瀏覽器
* { /* 給box-sizing設置顯示繼承 */ box-sizing: inherit; } html { box-sizing: border-box; } .some-widget { box-sizing: content-box; }
html根元素下全部元素(除獨自設置:如.some-widget
)的box-sizing
都是border-box
。dom
當向上繼承到頂點仍是沒找到值的話,就須要初始值了。佈局
background-color
的初始值爲 transparent
透明margin-left
的初始值爲 0background-color: initial
media
等等,好比當用戶打印時,加載media是打印樣式的css樣式,生成的聲明值可能會有一個或多個,好比一個p標籤匹配到了兩個選擇器 p{ font-size: 16px }
,p.text{ font-size: 1.2em }
width:400.2px
,轉化成width: 400px
,生成實際值,css求值完畢求strong標籤裏的font-size值?字體
<article> <p>卡爾斯巴德洞窟(Carlsbad Caverns)是美國的一座國家公園, 位於新墨西哥州東南部。遊客能夠經過自然入口徒步進入,也能夠 經過電梯直接到達<strong>230米</strong>的洞穴深處。</p> </article> <style> body { margin: 0; } article { font-size: 14px; line-height: 1.6; } p { font-size: 1.1em; } </style>
匹配strong標籤的選擇器,沒有,則使用繼承值或者初始值,strong標籤的父級是p標籤,相對值爲font-size: 1.1em
,由於font-size: 1.1em
是相對值,不能直接渲染到頁面裏,找到p的父級article
的font-size: 14px
,而後將相對值轉化爲絕對值font-size:15.4px
,在將絕對值轉化成整數值font-size:15px
,求出strong標籤裏font-size: 15px
。spa
<article> <h1>卡爾斯巴德洞窟</h1> <p>卡爾斯巴德洞窟(Carlsbad Caverns)是美國的一座國家公園, 位於新墨西哥州東南部。遊客能夠經過自然入口徒步進入,也能夠 經過電梯直接到達230米的洞穴深處。</p> </article> <style> body { margin: 0; } article { line-height: 150%; } h1 { font-size: 40px; } p { font-size: 14px; } </style>
因爲h1中沒有line-height
這個屬性,他會繼承向上找父級<article>
的line-height:150%
,是個相對值,因此要乘<article>
的line-height
計算值,在向上繼承<html>
的line-height:16px
(瀏覽器默認),因此最後的實際值是24px,自己字體是40px,因此折行時會重疊。code
把150%改爲1.5orm
對於百分數,會在resolving中轉換,把150%轉化成24px,可是設置行高爲1.5,他會在resloing找到article的line-height
爲1.5,而後在formatting中將1.5乘以本身ling-height獲得60px。htm