2017-05-25 54 views
-2

爲什麼#boxbody繼承border?我試圖在Chrome開發人員工具中檢查html源代碼,並注意到border未被繼承。爲什麼邊界不是從這裏繼承的?

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>The Box Model</title> 
<style> 

body { 
    background-color: gray; 
    margin: 0; 
    padding: 0px; 
    border: 10px solid black; 

} 

#box { 
    background-color: blue; 
    padding: 10px 10px 10px 10px; 
    width: 300px; 
} 

#content { 
    background-color: #90EE90; /*green*/ 
} 

h1 { 
    margin-bottom: 30px; 
} 

</style> 
</head> 
<body> 

<h1>Box Model</h1> 

<div id="box"> 
    <div id="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. </div> 
</div> 


</body> 
</html> 
+1

默認情況下,邊框不會被繼承。 – inarilo

+1

我在代碼中的任何地方都看不到'inherit' ..如果不指定它,它應該如何繼承? –

回答

3

加上這個border: inherit;它會繼承parent的border屬性。

CSS:

#box { 
    background-color: blue; 
    padding: 10px 10px 10px 10px; 
    width: 300px; 
    border: inherit; 
} 
1

需要在此的繼承財產。你可以添加 -

#box { 
    border: inherit; 
} 
1

在CSS ,「border」默認情況下不是繼承屬性。

相關問題