2011-10-11 200 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

做得好提供范例上的背景图像的对准相对于通过像素“停靠点”微调 –