跨浏览器清除浮动,IE6、IE7、Opera、FireFox通过

一个外部div,如果内部对象有float设置,产生了浮动,那么,外部div的高度不会随着内部对象而撑大
具体看例子:
/examples/clear.html

.clear { clear:both; height:0; overflow:hidden; line-height:1px;}
一直都是用

进行清除浮动,方便实用,又省事
现在想想,感觉总是有那么一点不妥,多出来一个div,貌似在结构上不是很规范。

于是重新整理了一下清除浮动的方法,老外写的文章很专业,哈哈:
How To Clear Floats Without Structural Markup
http://www.positioniseverything.net/easyclearing.html

.demo2 {border:1px solid #360;}
.demo2:after{ content:" "; visibility:hidden; display:block; height:0; overflow:hidden; clear:both;}
/* no ie mac \*/
* html .demo2 {height:1%;}
/* end */
*+html .demo2 {height:1%;} /* for ie7 */
.demo2 {display: inline-block;} /* for ie mac */

:after伪类,目前在IE6,IE7中都不能支持,IE8 bate不太清楚。。我还没有用到IE8。。
所以就有了针对IE的一些hack,除mac IE的hack:

/* no ie mac */
* html .demo2 {height:1%;}
/* end */

针对Mac IE的属性:
.demo2 {display: inline-block;} /* for ie mac */

在IE7竟然不支持* html div的方式:

*+html .demo2 {height:1%;} /* for ie7 */

这下好了。。。IE6、IE7、FireFox、Opera都通过了,至于Mac IE。。。我没有测试~~好在Mac IE的用户几乎为0吧。。

发表评论

Your email is never shared. Required fields are marked *

*
*