CSS:我不能将身体内容置于背景图像中心

时间:2012-10-22 13:05:54

标签: html css background css-float

我尝试在网站正文中添加背景,我想展示完整背景,并将网站内容集中在其中。

我使用了以下CSS,但无法居中:

body {
  margin: auto;
  background: url(../images/bggeneral.jpg) top center repeat;
  background-position: center;
  font-size: 100%;
  line-height: 1.0625em;
  color: #515151;
  width: 100%;
}

背景图片:http://www.comicar.ma/assets/images/bggeneral.jpg

我是否需要裁剪图像或类似的东西?

1 个答案:

答案 0 :(得分:4)

如果您不想重复身体图像,可以删除repeatmargin:0 auto应该被赋予容器div。

<强> HTML

<div class="wrapper">
Content
</div>​

<强> CSS

body {background: url(http://www.comicar.ma/assets/images/bggeneral.jpg) top center no-repeat; font-size: 100%; line-height: 1.0625em; color: #515151; width: 100%; }
.wrapper{width:700px; margin:0 auto}

LIVE DEMO