2016-11-20 62 views
-3

我想擺脫我的網站周圍的白色邊緣。我已設置#body #header和#html頁邊距:0;和填充:0;是否有人可以幫助與身體,標題和html設置在0的白色邊緣

下面是HTML代碼:

<DOCTYPE html> 
<html> 
<header> 
<link href="CSS/stylesheet.css" rel=stylesheet> 
</header> 
<body> 
<div id="bannertop"></div> 

</body> 
</html> 

而CSS:

#html{ 
    margin: 0 !important; 
    padding: 0 !important; 
} 
#header{ 
    margin: 0 !important; 
    padding: 0 !important; 
} 
#body{ 
    margin: 0 !important; 
    padding: 0 !important; 
} 
#bannertop{ 
    height: 200px; 
    width: 100%; 
    background-color: cadetblue; 
    margin-top:0px; 

} 

下面是該網站的picure Website

回答

-2

試試這個:

* { 
    margin: 0; 
} 

它應該在每個元素上設置所有邊距爲0。 你可以通過將它保留在你的CSS的開始並向其他元素添加不同的邊距

1

你需要從#html,body和header中刪除#,因爲#用於ID和。 for class difference between ID & Class

html,body{ 
    margin: 0 !important; 
    padding: 0 !important; 
} 
header{ 
    margin: 0 !important; 
    padding: 0 !important; 
} 

#bannertop{ 
    height: 200px; 
    width: 100%; 
    background-color: cadetblue; 
    margin-top:0px; 

} 
0

歡迎來到StackOverflow!

您沒有正確引用一些元素。 #選擇器(在你的CSS前面的html,bodyheader)目標元素用id屬性設置後的值爲#

由於您試圖引用沒有ID的HTML元素,因此您的CSS沒有正確定位元素。

要修復它,您必須刪除htmlbody前面的#。您還可以更簡潔,通過使用多個選擇這樣寫:

html, body { 
    margin: 0 !important; 
    padding: 0 !important; 
} 

FYI您在使用header代替head一個小的失誤。


如果你正在學習HTML和CSS我推薦以下資源:

0

身體和HTML之前刪除#

html{ 
 
    margin: 0 !important; 
 
    padding: 0 !important; 
 
} 
 
#header{ 
 
    margin: 0 !important; 
 
    padding: 0 !important; 
 
} 
 
body{ 
 
    margin: 0 !important; 
 
    padding: 0 !important; 
 
} 
 
#bannertop{ 
 
    height: 200px; 
 
    width: 100%; 
 
    background-color: cadetblue; 
 
    margin-top:0px; 
 

 
}
<DOCTYPE html> 
 
<html> 
 
<header> 
 
<link href="CSS/stylesheet.css" rel=stylesheet> 
 
</header> 
 
<body> 
 
<div id="bannertop"></div> 
 

 
</body> 
 
</html>