2013-01-01 114 views
1

我使用這個CSS把一張圖片到<body>移動身體的背景圖像

body { 
    background: url('picture.png') no-repeat; 
    background-size: contain; 
} 

圖片在瀏覽器窗口的頂部顯示,但我需要把這個圖像從幾個像素頂端。

我試過使用padding/margin-top: 20px;,但它沒有幫助我,圖像仍然在瀏覽器窗口的頂部。

如何將body標籤的背景圖像從頂部向下移動幾個像素?

注:我需要在身體標記中的圖片。

回答

5

您需要改用background-position

body { 
    background: url('picture.png') no-repeat; 
    background-position: 0 20px; 
    background-size: contain; 
} 
+0

如此快速和簡單的解決方案,謝謝'BoltClock'。 – user984621

1

您可以使用CSS背景位置屬性,

例如

body { 
    background: url('picture.png') no-repeat; 
    background-position: 0px 50px; /* This makes the image appear 50px from top */ 
    background-size: contain; 
}