:几种常用的清浮动方法

来源:百度文库 编辑:九乡新闻网 时间:2024/07/14 13:06:07
用空标签清除
.clr {clear: both;}


Left



弊端:增加了无意义的结构元素

使用 overflow 属性
#layout {overflow:hidden;zoom:1;}


Left


zoom:1″用于兼容IE6,
弊端:当页面有浮动层比较容易出问题
 
使用 :after (非 IE 浏览器)
#layout:after{
display: block;
clear: both; content: "";
visibility:hidden; height: 0;
}


Left


注:使用 :after 需要注意几点,设置高度为零(height: 0;);content 是必须的,但其值必须为空。

 

使用display属性
#layout{
display:table;
height:1%;
}


Left


 

例外,

对于浏览器来说,Margin是兼容性最差的一个属性。因此,只要条件允许,应该尽可能的使用Padding属性。

 

始终让 Firefox 显示滚动条的方法:html {overflow:-moz-scrollbars-vertical;}

 

删除链接上的虚线框:a:active, a:focus {outline:none;} 只对FF有效,

IE里需通过js控制:

window.onload=function()
{
for(var ii=0; iidocument.links[ii].onfocus=function(){this.blur()}
}