1.浮动元素与父盒子的关系:子盒子的浮动参照父盒子对齐;不会与父盒子的边框重叠,也不会超过父盒子的内边距。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.father {
width: 500px;
height: 500px;
background-color: pink;
}
.son {
float: right;
width: 200px;
height: 200px;
background-color: purple;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
2.浮动元素与兄弟盒子的关系:在一个父级盒子中,如果前一个盒子是浮动的,那么当前盒子会与前一个盒子的顶部对齐;如果前一个兄弟盒子是普通流的,那么当前盒子会显示在前一个兄弟盒子下方。(浮动只会影响当前的或者后面的盒子,不会影响前面的标准流)。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.father {
width: 500px;
height: 500px;
background-color: pink;
}
.damao {
/* float: left; */
width: 150px;
height: 150px;
background-color: purple;
}
.ermao {
float: right;
width: 200px;
height: 200px;
background-color: skyblue;
}
</style>
</head>
<body>
<div class="father">
<div class="damao"></div>
<div class="ermao"></div>
</div>
</body>
</html>