Html 居中背景+;整版容器

Html 居中背景+;整版容器,html,css,Html,Css,我想在页面中央放置一个背景(宽度=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

我想在页面中央放置一个背景(宽度=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;}
如何获得居中的背景图像和完整的页面容器

谢谢

基本CSS

background: #000 url(../../../images/background.jpg) no-repeat center center;
注意:css中不需要引号。事实上,在某些情况下,使用引号时可能会出现问题。

基本CSS

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

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

将您的背景规则更改为:

background:#000 url(images/background.jpg) center center no-repeat;
或者,如果要将其居中放置在页面顶部,请执行以下操作:

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

然后您可以删除
边距:0 auto
,因为宽度为100%的边距是无用的。

将您的背景规则更改为:

background:#000 url(images/background.jpg) center center no-repeat;
或者,如果要将其居中放置在页面顶部,请执行以下操作:

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

然后您可以删除
边距:0自动
,因为它的宽度为100%时没有用。

边距:0自动是一个输入错误(ctrl c+ctrl v issue=D)。我从来没有想过
center
在某个时候会有用,所以我最终在没有测试的情况下放弃了解决方案是一个输入错误(ctrl c+ctrl v issue=D)。我从来没有想过
center
在某个时候会有用,所以我没有测试就放弃了这个解决方案。