DIV背景图片在Firefox下不显示通过overflow:auto可解决

前端技术 2023/09/08 CSS
在一个大的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;
}


此代码是左右两栏排版,利用父DIV(footer)的背景图片做子DIV(footer_left)的背景,来达到左右两栏高度对齐。
解决办法:
这是因为你的#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;
}

本文地址:https://www.stayed.cn/item/22098

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。