六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 176|回复: 0

(转)CSS clearfix

[复制链接]

升级  46.33%

101

主题

101

主题

101

主题

举人

Rank: 3Rank: 3

积分
339
 楼主| 发表于 2013-2-8 00:14:55 | 显示全部楼层 |阅读模式
原文地址如下:
http://www.webtoolkit.info/css-clearfix.html

See also:
http://www.codecto.com/2011/02/css-clearfix-float/

CSS clearfix

The problem happens when a floated element is within a container box, that element does not automatically force the container’s height adjust to the floated element. When an element is floated, its parent no longer contains it because the float is removed from the flow. You can use 2 methods to fix it:

{clear: both;}
clearfix

Once you understand what is happening, use the method below to “clearfix” it.

DEMO

Source code for webtoolkit.clearfix.css

.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}

.clearfix {
display: inline-block;
}

html[xmlns] .clearfix {
display: block;
}

* html .clearfix {
height: 1%;
}

--------------------------------------------------------
以下是另外一种 clearfix 的写法,来处 jQuery UI:

.clearfix:before, .clearfix:after { content: ""; display: table; }
.clearfix:after { clear: both; }
.clearfix { zoom: 1; }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表