2016-09-30 23 views
0

試圖創建網站標題,有一個在左邊/頂部有一個小的空間,不會消失

@import 'https://fonts.googleapis.com/css?family=PT+Sans'; 
 
* { 
 
    font-family: 'PT Sans', sans-serif; 
 
} 
 
#headerpanel { 
 
    display: block; 
 
    background-color: red; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding 0px; 
 
    border: 0px; 
 
}
<title>Test Site</title> 
 
<body> 
 
    <div id="headerpanel"> 
 
    TEST 
 
    </div> 
 
</body>

我試圖做的是建立一個「頭」,將自啓動非常左側的網站在最右邊20px左右。

Space?

但是當我測試的網站,我看到有一個在左上... 我該如何擺脫它這個小空間?

+2

集'保證金:0'到'body' – kukkuz

回答

2
body,html { 
    margin:0px; 
    padding:0px; 
} 
1

您只需要重置瀏覽器的默認邊距樣式body

body { 
    margin: auto; 
} 

在瀏覽器的IDE /開發工具看一下你的盒子模型通過「已計算」選項卡。

enter image description here

0

添加在你的CSS

body{ 
    margin:0; 
} 
0

清除體內緣左側以下

@import 'https://fonts.googleapis.com/css?family=PT+Sans'; 
 

 
* { 
 
    font-family: 'PT Sans', sans-serif; 
 
} 
 

 
#headerpanel { 
 
    display: block; 
 
    background-color: red; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding 0px; 
 
    border: 0px; 
 
} 
 
body{margin: 8px 0px; }
<title>Test Site</title> 
 
<body> 
 
<div id="headerpanel"> 
 
TEST 
 
</div> 
 
</body>

0

無論是我誤解你的問題或全部的其他答案哈我已經這樣做了。我一直認爲margin: 0;解決了這個問題,它確實在一些瀏覽器上,但Safari和Chrome僅舉幾個添加這個小邊框。您應該使用top: 0; left: 0;的代碼與頁面邊緣對齊。

@import 'https://fonts.googleapis.com/css?family=PT+Sans'; 
 
* { 
 
    font-family: 'PT Sans', sans-serif; 
 
} 
 
#headerpanel { 
 
    position: fixed; 
 
    display: block; 
 
    background-color: red; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0;/* since we are moving it left a little, we use right: 0; instead of width: 100%; */ 
 
    margin: 0px; 
 
    padding: 0px; 
 
    border: 0px; 
 
}
<title>Test Site</title> 
 
<body> 
 
    <div id="headerpanel"> 
 
    TEST 
 
    </div> 
 
</body>

相關問題