浮动产生的问题
当父亲没有给宽高时,子盒子只要使用了浮动就会脱标,导致父盒子变小,做不到在商城页面展示商品的效果。(就是想让子盒子脱标了,即使用了浮动后,让父盒子的大小随着子盒子的多少和大小来改变。)
代码示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>清除浮动</title>
<style>
.out{
width: 800px;
border-color: darkmagenta;
border-style: solid;
border-width: 2px;
}
.daMao{
background-color:burlywood;
width: 200px;
height: 200px;
margin: 0 auto;
float: left;
}
.erMao{
background-color:cornflowerblue;
width: 200px;
height: 200px;
margin: 0 auto;
float: left;
}
</style>
</head>
<body>
<div class="out">
<div class="daMao">大毛</div>
<div class="erMao">二毛</div>
</div>
</body>
</html>
上述问题是由于子盒子脱标了导致父盒子没有了高度。