清除浮动的两种解决方案

来源:互联网 发布:dd命令 备份linux系统 编辑:程序博客网 时间:2024/06/05 21:15
浮动一直是我们编写网页最常用的方法,但是也是最不听话的,一不小心会乱跑,虽然有万能的float闭合div多写一个可以解决掉,但是为了清除浮动而多出来一个空的div实在看着不爽,这里我在网上找到了两种解决的办法,相信很多朋友已经在用了,不过还是列出来,以备后用。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>清除浮动的两种解决方案</title>
<style type="text/css">
ul{
list-style:none;
height:auto;
margin:0;
padding:0;
background-color:#436973;
}
li{
float:left;
width:80px;
height:120px;
background-color:#83B1DF;
}
.demo{
clear:both;
border:1px solid #FF00FF;
margin-bottom:5px;
}
.overflow{
height:auto;
_height:200px;
min-height:200px;
overflow:auto;
zoom:1;
_overflow:visible;
}
.clear:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}/*for w3c*/
.clear {
zoom:1;
}/*for IE*/
</style>
</head>
<body>
<div class="demo">
<ul class="overflow">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
</div>
<div class="demo">
<ul class="clear">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
</div>
</body>
</html>



原创粉丝点击