【问题标题】:IE background display problemIE后台显示问题
【发布时间】:2010-09-29 07:55:52
【问题描述】:

我正在为我的教会创建一个网站,但无法在 IE 中正确显示。似乎我的 div “sidebox” 的背景位置被 “margin: 0 auto;” 覆盖了因为背景显示居中而不是右侧,这将网站向右移动。

代码如下:

.sidebox {
margin: 0 auto;
background-image: url(images/bg-container-right.jpg);
background-repeat: no-repeat;
background-position: bottom right !important;
position: absolute;
left: 0px;
width: 960px;

}

.boxhead {
    background-image: url(images/bg-container-top.jpg);
    background-repeat: no-repeat;
    background-position: top right;
    height: 37px;
}

.boxbody {
    background-image: url(images/bg-container-left.jpg);
    background-repeat: no-repeat;
    background-position: bottom left !important;
    width: 25px !important;
}

.boxtopcorner {
    background-image: url(images/bg-container-top-right.jpg);
    background-repeat: no-repeat;
    background-position: top left;
    width: 25px;
    height: 37px;
}

<div class='sidebox' style='border: 1px solid;'>
I'm in the box
    <div class='boxhead'>
        <div class='boxtopcorner'></div>
    </div>
    <div class='boxbody' style='height: 750px;'>
        <!-- Content Goes Here -->
    </div>
</div>

下面是运行站点的链接。您可以看到它在 FF 和 Safari 中运行良好,但在 IE 中却不行。我上面的代码没有内容,删除它并不能解决问题。 Running page

【问题讨论】:

    标签: internet-explorer margin


    【解决方案1】:

    我会采取一种完全不同的方法来处理你如何分割背景图像。

    1. 为带圆角的阴影创建顶部和底部图像。将这些用作顶部和底部的背景(好像这还不明显)。
    2. 为两侧的阴影创建一个“长”1 像素高的图像。将其用作页面整个内容区域的背景。
    3. 尽量不要使用绝对定位。可以使用浮动创建相同的布局。例如:

    .container { 宽度:960px;边距:0 自动; }

    .header { width: 960px; height: 20px; background: url(top.jpg) no-repeat; }
    
    .footer { width: 960px; height: 20px; background: url(bottom.jpg) no-repeat; }
    
    .body { width: 960px; background: url(body.jpg) repeat-y; }
    
    <div class='container'>
    
      <div class='header'>&nbsp;</div>
    
      <div class='body'>
    

    内容放在这里...使用浮动来创建列而不是绝对定位。

      </div>
    
      <div class='footer'>&nbsp;</div>
    
    </div>
    

    【讨论】:

    • 感谢您的建议。我首先构建它以便它可以接受任何宽度和任何高度。但是,当我决定使用固定宽度时,我忘记了我可以按照您建议的方式进行操作。我将来可能会修复它。谢谢。
    【解决方案2】:

    通过 IE 开发者工具栏查看它,它使 .sidebox 居中对齐。将其更改为向左似乎可以解决问题。

    .sidebox {
      ...
      text-align: left;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-20
      • 1970-01-01
      • 2012-01-31
      • 2013-12-18
      • 1970-01-01
      相关资源
      最近更新 更多