`
wind13
  • 浏览: 18653 次
  • 性别: Icon_minigender_1
  • 来自: 西安
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

CSS中float引起层飘出上级层的解决方案,清除浮动的好方法。

阅读更多
 为了解决这个问题,从网上找到这篇文章:CSS的十八般技巧
其中第十三条提到解决方案,于是看到这篇:How To Clear Floats Without Structural Markup
解决方案好象比较麻烦,如下:
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}

.clearfix {display: inline-block;}

/* Hides from IE-mac \*/
* html .clearfix {height: 1%;}
.clearfix {display: block;}
/* End hide from IE-mac */
经我多次尝试,修改如下:
.clearfix {
    display: block;
    margin: 0px;
    clear: both;
    padding: 0px;
    visibility: hidden;
    background-color:#666666;
    border:0px none #FFFFFF;
}
.clearfix:after {
    height: 0px;
}

使用方法:
在所有浮动层之后加上这个层
 <div class="clearfix"></div>

在IE和FireFox测试OK,我想就够了,呵呵……
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics