在下面的代碼中,我試圖讓h1元素有一個頂邊距。當我將位置設置爲在css中內聯時,margin-top不顯示。但是,當我將其更改爲內聯塊時,它確實如此。我想知道是否有人可以解釋爲什麼會出現這種情況。謝謝。爲什麼margin-top與inline-block一起工作,而不是inline?
編輯:下面是的jsfiddle代碼:http://jsfiddle.net/pjPdE/
這裏是我的HTML:
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="MyFirstWebsite.css">
<title>
Max Pleaner's First Website
</title>
</head>
<body>
<h1>Welcome to my site.</h1>
</body>
</html>
而這裏的CSS
body {
background-image:url('sharks.jpg');
}
h1 {
background-color:#1C0245;
display:inline;
padding: 6.5px 7.6px;
margin-left:100px;
margin-top:25px;
}
浮動它有幫助。 –