css - IE7中的 float div问题

标签 css internet-explorer-7 css-float background-image

我正在尝试使用带有 float div 的第二个背景图像,但它在 IE6 和 7 中不起作用

我知道 float div 在 IE7 和更低版本的 * 中很麻烦,但我真的需要让它工作。

这是我使用的代码

<body style="background-color:#FFFFFF; margin-top:0px; margin-right:0px;" topmargin="0"       rightmargin="0" leftmargin="0">
<div id="bg2" style="float:right; top:0px; width:450px; height:151px; margin-right:0px; padding-right:0px; font-size:1px; overflow:visible; background-image:url(images/back2.jpg);"></div>

<center>

<div style="position:relative; top:0px; width:1050px; margin:0px; padding:0px; vertical-align:top; text-align:left;">
....(huge div container)...

我还尝试从包含第二个背景图像的 div 中删除 width 属性,然后获取窗口大小并将差异添加到容器 div 作为 Jquery 的左属性。它在所有 IE 版本中都运行良好,但这次在 Chrome 上不行

here is a print screen

有什么想法吗?

最佳答案

..其实我想我找到了我的解决方案。

我试图将容器居中对齐

我知道是否没有足够的空间让 div 适合窗口,导致 IE6 和 7 出现问题,所以我使用 Jquery css 属性来确定 float 背景图像 div 的宽度。

<script type="text/javascript">
$(document).ready(function() {
    if($(document).width() > 1050){          //Container's width:1050px
        var wd = document.body.clientWidth;
        wd = Math.round((wd-1050)/2); 
        $("#bg2").css("width" , wd);
        $("#container").css("left" , wd);
    }
});
</script>

和 html...

<body style="background-color:#FFFFFF; margin: 0px; padding: 0px;">
<p align="right">
<div id="bg2" style="position:absolute; float:right; top:0px; right:0px; height:151px; margin:0px; padding:0px; font-size:1px; overflow:visible; background-image:url(images/back2.jpg);"></div>
<div id="container" style="position:absolute; top:0px; width:1050px; margin:0px; padding:0px; vertical-align:top; text-align:left;">
....(huge div container container)....

关于css - IE7中的 float div问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4535447/

相关文章:

CSS 菜单在 IE7 中左对齐 - 如何在所有浏览器(IE7、IE8、firefox 等)中使菜单居中

html - vertical-align 不使文本居中

css - float 如何用于定位列?

html - 在 Angular/HTML 中,如何在表格中显示鼠标悬停图标

html - 是否可以更改文本区域中制表符的宽度?

html - IE 和 Edge 中无法解释的网格行高

windows - IE6 和 IE7 独立版 : What do they render differently?

css - 导航栏样式有问题

css - 使用标准和怪癖框模式让 IE7 呈现

css - 需要将 Pinterest 板向右浮动