73 lines
1.4 KiB
HTML
73 lines
1.4 KiB
HTML
|
<!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>
|
||
|
.parent {
|
||
|
width: 800px;
|
||
|
/* height: 400px; */
|
||
|
border: 10px solid blue;
|
||
|
}
|
||
|
.parent::after {
|
||
|
/* 利用伪类清除父盒子的浮动 */
|
||
|
content: "";
|
||
|
display: block;
|
||
|
clear: both;
|
||
|
}
|
||
|
.box1 {
|
||
|
float: left;
|
||
|
width: 250px;
|
||
|
height: 80px;
|
||
|
background-color: #ed7d31;
|
||
|
}
|
||
|
.box2 {
|
||
|
|
||
|
width: 400px;
|
||
|
height: 100px;
|
||
|
background-color: #70ad47;
|
||
|
}
|
||
|
.box3 {
|
||
|
|
||
|
width: 200px;
|
||
|
height: 100px;
|
||
|
background-color: #7030a0;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
</style>
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
|
||
|
<div class="parent">
|
||
|
<div class="box1">box1</div>
|
||
|
<div class="box2">box2</div>
|
||
|
<div class="box3">box3</div>
|
||
|
|
||
|
<div style="clear: both;"></div>
|
||
|
<!-- 清除父盒子浮动 -->
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</body>
|
||
|
|
||
|
</html>
|
||
|
<!--
|
||
|
文档流
|
||
|
|
||
|
浮动
|
||
|
1.浮动单元 处于浮动
|
||
|
2.不会遮挡内容(文本内容)
|
||
|
3.要会想象有个眼睛
|
||
|
4.不占原有文档流的位置(可以给父盒子清除浮动)
|
||
|
|
||
|
|
||
|
-->
|