您的位置:首页 > 其它

使用zoom、overflow解决IE6、IE7、火狐浏览器下嵌套容器清除浮动问题

2014-04-13 10:09 483 查看
  我们经常遇到一个容器外面套一个边框,边框高度随容器高度变化,但是当边框内容器设置了浮动属性后,外框就不跟随变化,这时就需要清除浮动。给外边框容器加上overflow:auto的属性,可以解决IE7和火狐浏览器下的清除浮动问题,但是IE6下不生效,我们需要使用IE的一个私有属性zoom使IE5.5 的浏览器达到外框跟随变化的效果。

  需要注意的几个细节问题,例如我们建立一个样式为text的容器,宽200象素,高度自适应,外面包一个样式为content的10象素的外框。(如图1)

图1



代码如下:

以下是引用片段:

<style type="text/css">

.content{ border:10px solid #F00;}

.text{ width:200px; height:300px; background:#000;}

</style>

<body bgcolor="#火狐浏览器火狐浏览器火狐浏览器">

<div class="content">

<div class="text"></div>

</div>

</body>

  如果我们为text容器设置了左浮动的属性,并将content容器定义了200象素的宽,就需要为content容器增加overflow:auto属性,以清除text容器的浮动。否则火狐浏览器下则会出现问题。(如图2)

图2


screen.width*0.7) {this.resized=true; this.width=screen.width*0.7;
this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to
zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" border="0">

代码如下:

以下是引用片段:

<style type="text/css">

.content{ border:10px solid #F00; width:200px; overflow:auto;}

.text{ width:200px; height:300px; background:#000; float:left;}

</style>

<body bgcolor="#火狐浏览器火狐浏览器火狐浏览器">

<div class="content">

<div class="text"></div>

</div>

</body>

  除此之外还有一种比较特殊的情况,如果在不设定content宽度的情况下,仅仅使用overflow:auto,在IE5.5 下是无法实现清除浮动的效果的。为此我们需要使用一个IE的私有属性zoom来使IE下达到所需效果。

代码如下:

以下是引用片段:

<style type="text/css">

.content{ border:10px solid #F00; overflow:auto; zoom:1;}

.text{ width:200px; height:300px; background:#000; float:left;}

</style>

<body bgcolor="#火狐浏览器火狐浏览器火狐浏览器">

<div class="content">

<div class="text"></div>

</div>

</body>

from:http://51ui.blog.163.com/blog/static/61900372200828114494/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐