CSS ZOOM 作用[IE6下清除浮动] (2)

function init(){
    if(data_provinces&&data_provinces.length>0){
        for(var i=0;i<data_provinces.length;i++){
            var li=document.createElement("li");
            var a=document.createElement("a");
            li.appendChild(a);
            $("ul_province").appendChild(li);
            a.innerHTML=data_provinces[i].Name;
            a.Code=data_provinces[i].Code;
            a.Unis=data_provinces[i].Unis;
            a.href="javascript:void(0);";
            if(data_provinces[i].Name.length>2)li.className="spWidth";
        }
    }
}

function $(id){return document.getElementById(id);}

</script>

上面的HTML,如果在IE6下显示会存在清除浮动的问题,在IE7,8下由于ul有overflow:hidden的设置,会清除浮动,IE6下在加上了zoom:1后才会清除浮动。

转载一篇也是说明这个问题的文章:

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


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


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




图1

CSS ZOOM 作用[IE6下清除浮动]

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\';}" onmousewheel="return imgzoom(this);" alt="Click here to open new window CTRL+Mouse wheel to zoom in/out">


   代码如下:
以下是引用片段:
<style type="text/css">
.content{ border:10px solid #F00;}
.text{ width:200px; height:300px; background:#000;}
</style>

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


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



图2

CSS ZOOM 作用[IE6下清除浮动]

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\';}" onmousewheel="return imgzoom(this);" alt="">

   代码如下:
以下是引用片段:
<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>
<div></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>
<div></div>
</div>
</body>

-----------------------------------------------

经常会看到说ZOOM会触发haslayout属性,这是个什么属性呢?下面的文章有详细介绍:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzpdjx.html