为什么父div没有被撑开

为什么父div没有被撑开:
建议:尽可能的手写代码,可以有效的提高学习效率和深度。
在正常情况下,如果父对象没有设置高度,子对象能够将子对象撑开,但是如果子对象浮动且没有清除浮动的话,在IE8或者FF浏览器,父对象并不能够被撑开,在IE6下可以撑开。
代码实例: 

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<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.softwhy.com/" />
<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>

 原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4699

原文地址是:http://www.softwhy.com/divcss/

猜你喜欢

转载自softwhy.iteye.com/blog/2265977