HTML代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<style type="text/css">
#parent-div {
border: 2px solid red;
}
#child-div {
float: left;
width: 200px;
height: 70px;
border: 2px solid blue;
}
.clear-float {
clear: both;
}
</style>
</head>
<body>
<div id="parent-div">
<div id="child-div"></div>
<div id="child-div"></div>
<div class="clear-float"></div>
</div>
</body>
</html>
其中,<div class="clear-float"></div>标签取消前两个子标签的浮动效果,则父标签parent-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>temp</title>
<style type="text/css">
*{
margin:0;
padding:0;
zoom:1;
}
ul{
list-style:none;
padding:5px;
overflow:hidden;
background-color:#eee;
}
li{
float:left;
line-height:100px;
margin:0 4px;
display:inline;
border:1px solid #ccc;
background-color:#fff;
}
</style>
</head>
<body>
<ul>
<li>aaaaa</li>
<li>bbbbbbb</li>
<li>aaaaa</li>
<li>bbbbbbb</li>
<li>aaaaa</li>
<li>bbbbbbb</li>
<li>aaaaa</li>
<li>bbbbbbb</li>
</ul>
</body>
</html>