DIV背景图片在Firefox下不显示,IE下正常

来源:百度知道 编辑:UC知道 时间:2024/05/25 01:59:11
在一个大的div里有2个横列(DIV),并且在大的div里加入背景图片。可是改好后,在Firefox下却无法正确显示背景图片。代码是这样的:

1.HTML(样本):

<div id="footer">
<div id="footer_left">Content1</div>
<div id="footer_right">Content2</div>
</div>

2. CSS:
#footer {
width:730px;
background-image: url(../images/bg.jpg);
background-repeat: repeat-y;
}
#footer_left {
float:left;
width:230px;
}
#footer_right{
float:left;
width:500px;
}

这是因为你的#footer_left 和#footer_right加了float:left,在FF里如果里面的元素加了float:left(right),它就不会被撑开的,也就是说的它的高度是0,如果正常显示,必须加上:overflow:auto,即:#footer {
width:730px;
background-image: url(../images/bg.jpg);
background-repeat: repeat-y;
overflow:auto;
}

sonichu正解,
或者把背景图直接写在div的样式里

<div id="footer">
<div id="footer_left" style="background-image:url(images/bg_images/bg_200707090606106.jpg)">Content1</div>
<div id="footer_right">Content2</div>
</div>