2016-12-04 54 views
0

讓我解釋一下:我想填充整個身體的一部分,例如如何填充身體的整個區域?

<html> 
    <head> 
     <title>Fill an entire area</title> 
    </head> 
    <body> 
     <div id="header"> 
     This area is red. 
     </div> 
     <div id="middle"> 
     </div> 
     <div id="footer"> 
     </div> 
    </body> 
</html> 

在div標籤「頭」應該是紅色的,但如果我寫

#header { 
    position: relative; 
    background-color: red; 
} 

頭會變成紅色,但也有它周圍的小空格。

enter image description here

相反的話,我想它不能包含空格。有沒有一種方法可以在不使用Bootstrap的情況下在CSS中執行此操作?

enter image description here

對不起,如果有一個類似的問題。我不知道如何解釋我的問題。

+3

你嘗試'體{保證金:0;填充:0}'? – Akshay

+0

是你的整個HTML文件嗎?在這種情況下,我會***強烈建議使用文檔類型聲明。它將防止各種離子兼容性問題。 –

+0

您是否在瀏覽器中檢查了您的代碼元素? – Obink

回答

1

我想這是因爲默認的身體marginmargin#header的,使用此:

body, #header { 
    margin: 0; 
} 
1

margin:0;padding:0添加到身體應該解決您在這裏面臨的問題。