2011-10-11 201 views
41

我已經被設置爲我的網站上的背景圖像(作爲<body>背景圖像)500×500一像素的圖片,但我需要這個圖像位於網頁的右下角。我怎樣才能做到這一點?如何在右下角放置背景圖片? (CSS)

謝謝(用CSS方法更好)。

回答

80

Voilla:

body { 
    background-color: #000; /*Default bg, similar to the background's base color*/ 
    background-image: url("bg.png"); 
    background-position: right bottom; /*Positioning*/ 
    background-repeat: no-repeat; /*Prevent showing multiple background images*/ 
} 

背景特性可以被組合在一起,在一個背景屬性。 參見:https://developer.mozilla.org/en/CSS/background-position

+1

Thnx,今天我幫了我很多安靜))) – Ilja

+0

不工作,當背景圖像高於屏幕高度... – Legionar

+0

@Legionar適用於我,在Chrome 43和Firefox 38中很好。 –

7

你嘗試類似:

body {background: url('[url to your image]') no-repeat right bottom;} 
9

爲更精確的定位:

 background-position: bottom 5px right 7px; 
+1

做得好提供範例上的背景圖像的對準相對於通過像素「停靠點」微調 –