【问题标题】:CSS: I can't center the body content in the background imageCSS:我无法在背景图像中居中正文内容
【发布时间】:2012-10-22 21:32:06
【问题描述】:

我尝试为网站正文添加背景,我想显示完整背景,并将网站内容居中放置在其中。

我使用了以下 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

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

【问题讨论】:

    标签: html css background css-float


    【解决方案1】:

    如果你不想重复身体形象,你可以删除repeat。并且margin: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

    【讨论】:

      猜你喜欢
      • 2016-11-21
      • 2011-02-08
      • 2023-04-01
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2017-11-23
      • 1970-01-01
      相关资源
      最近更新 更多