为什么父div没有被撑开:
在正常情况下,如果父对象没有设置高度,子对象能够将子对象撑开,但是如果子对象浮动且没有清除浮动的话,在IE8或者FF浏览器,父对象并不能够被撑开,在IE6下可以撑开。
代码实例:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.51texiao.cn/" />
<title>蚂蚁部落</title>
<style type="text/css">
.parent{
border:1px solid red;
width:500px;
}
.first,.second{
float:left;
height:100px;
width:100px;
border:1px solid blue
}
</style>
</head>
<body>
<div class="parent">
<div class="first"></div>
<div class="second"></div>
</div>
</body>
</html>
以上代码在IE6下可以撑开父div,但是在IE8或者FF浏览器下不能够被撑开。解决方法就是清除浮动。代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.51texiao.cn/" />
<title>蚂蚁部落</title>
<style type="text/css">
.parent{
border:1px solid red;
width:500px;
overflow:hidden
}
.first,.second{
float:left;
height:100px;
width:100px;
border:1px solid blue
}
</style>
</head>
<body>
<div class="parent">
<div class="first"></div>
<div class="second"></div>
</div>
</body>
</html>