html:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../css/reset.css">
<link rel="stylesheet" href="../css/66clear.css">
</head>
<body>
<div class="d1">1</div>
<div class="d2">2</div>
<div class="d3">3</div>
</body>
</html>
css:
(1)当两个块上下对齐时,上面那个块设置为float,那么下面会移动上面去
(2)为了消除这种影响,使用clear; 使得下面那个块不受float的影响。 具体的作用是,浏览器会自动设置下面块的 margin-top: x;x等于上面块的总高度
(3)clear: left; right; both; both是指,取当前所有float块最大的总高度为值,设置margin-top;
代码:
.d1 {
width: 300px;
height: 300px;
font-size: 30px;
background-color: pink;
float: left;
}
.d2 {
width: 500px;
height: 500px;
background-color: royalblue;
float: right;
}
.d3 {
font-size: 30px;
width: 300px;
height: 300px;
background-color: rebeccapurple;
clear: both;
}
效果