讲讲自己试的浮动元素占位情况。
<!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>Document</title>
<style>
* {
margin: 0px;
padding: 0px;
}
div.one {
background-color: red;
width: 450px;
}
img {
width: 200px;
float: right
}
.two{
width:100px;
height:100px;
background-color: green;
display: inline-block;
}
.three{
width:100px;
height:100px;
background-color:blue;
display: inline-block;
}
.four{
width:100px;
height:100px;
background-color: gold;
display: inline-block;
}
</style>
</head>
<body>
<div class="one">
<img src="img/1.jpg" alt="">
<div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>
</div>
</div>
</body>
</html>
效果展示:
总结:浮动的盒子不占用原来的位置,它下面的盒子会上来占用它原来的位置。浮动了的盒子变成行内块元素,占用现在的位置。
我之前的理解错了,以为浮动的盒子悬浮在上面,它后面的盒子上来占用位置,被浮动的盒子覆盖,以为浮动的盒子完全不占位置的,其实还是站位置的,只是可能不是占原来的位置。