浮动(float)是一个定位属性,用于使元素脱离正常文档流并浮动在它父容器的左侧或者右侧。
float设置元素在水平浮动,意味着只能左右浮动而不能上下浮动。
浮动可以相当于给了一个z轴的值,是浮动的元素会会覆盖住同一位置的其他元素
如:
<!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>
#one{
width: 100px;
height: 100px;
float: left;
background-color: coral;
}
</style>
</head>
<body>
<div id="one"></div>
<div style="background-color: crimson;"></div>
</body>
</html>
就只能看到第一个div而第二个就被覆盖住。