2012-01-26 22 views
0

我想提出一个背景(宽度= 1250px)为中心的网页上,但容器,应该有浏览器中心的背景+全页容器

该中心的背景宽度:

#container{margin:0 auto;background:#000 url("images/background.jpg") no-repeat;width:1250px;;} 

而这个设置容器的宽度=浏览器

#container{margin:0 auto;background:#000 url("../../../images/background.jpg") no-repeat;width:100%;position:relative;} 

如何获得居中的背景图像和整页容器?

谢谢!

回答

2

你的背景规则改成这样:

background:#000 url(images/background.jpg) center center no-repeat; 

或者,如果你想在页面的顶部居中,做到这一点:

background:#000 url(images/background.jpg) center top no-repeat; 

然后你就可以删除margin: 0 auto,因为它是无用宽度为100%。

+0

'margin:0 auto;'是一个错字(ctrl c + ctr v issue = D)。我从来没有想过'中心中心'有一段时间会有用,所以我最终放弃了没有测试的解决方案。 –

2

基本CSS

background: #000 url(../../../images/background.jpg) no-repeat center center; 

注意:你不需要在CSS引号。事实上,在某些情况下,使用引号时可能会出现问题。