2016-12-29 48 views
3

我用一個簡單的HTML代碼,背景圖片設置爲我的網頁,但它仍然顯示我在頁面的頂部的自由空間,我想生活中使用此代碼的背景圖像,它被提升到了,你能確定我的,是它的正確方法,還是有和我現有的CSS代碼的任何問題?如何在背景圖像刪除此頂層空間?

margin-top:-20px 

我的CSS代碼,

<style> 
.bg-image { 
    left: 0; 
    right: 0; 
    height: 200%; 
    background-image: url("/bg.jpg"); 
    background-position: 0px 0px; 
    position: fixed; 
    background-size: cover; 
    margin-top:-20px; 
} 

我的HTML代碼:

<html> 
<head> </head> 
<body> 
    <div class="bg-image"></div> 
</body> 
</html> 

回答

2

主體部分將調用內部分歧,所以一定要確保對身體的利潤,如果我們設置體margin:0px; padding:0px;然後將觸動瀏覽器的頂部。

試試這個代碼的CSS代碼中,

body{ 
    padding: 0px; 
    margin: 0px; 
} 
+0

謝謝,這是爲我工作。 – user7354735