当一个div的子级用了float浮动时,这个div的高度就不受子级div高度的影响了。 如:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>父div不自适应高度实例</title>
</head>
<style> .father { width:500px; border:1px solid #000; padding:10px}
.children_1 { width:220px; height:100px; background:#0066CC}
.children_2 { width:230px; height:100px; background:#F9F900}
.fl { float:left; }
.fr { float:right; } </style>
<body>
<div class="father">
<div class="children_1 fl"></div>
<div class="children_2 fr"></div>
</div>
</body>
</html>
运行结果:
这是因为css float的响应,有三种方式可以解决这个问题。
###方法一:对父级设置固定高度 此方法可用于能确定父级div内子级对象高度。 假如以上案例,我们知道内部div高度100px,那对父级设置css height为100px看看效果。