<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
*{padding: 0px;margin: 0px;}
.box1{
background-color: red;
}
.box2{
background-color: green;
}
.box1 p
{
width: 100px;
background-color: yellow;
}
.box2 p
{
width: 100px;
background-color: pink;
}
p
{
float: left;
}
.wall
{
clear: both;
}
.h20{
height: 20px;
background-color: skyblue;
}
</style>
</head>
<body>
<!--
1.清除浮动的第三种方式
隔墙法
2.外墙法
2.1在两个盒子中间添加一个额外的块级元素
2.2给这个额外添加的块级元素设置clear: both;属性
注意点:
外墙法它可以让第二个盒子使用margin-top属性
外墙法不可以让第一个盒子使用margin-bottom属性
为什么第一个盒子不能使用margin-bottom: 30px;,
因为已经到顶了。
-->
<div class="box1">
<p>我是文字1</p>
<p>我是文字1</p>
<p>我是文字1</p>
</div>
<div class="wall h20"></div>
<div class="box2">
<p>我是文字1</p>
<p>我是文字1</p>
<p>我是文字1</p>
</div>
</body>
</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>
<style type="text/css">
*{padding: 0px;margin: 0px;}
.box1{
background-color: red;
margin-bottom: 30px;
}
.box2{
background-color: green;
}
.box1 p
{
width: 100px;
background-color: yellow;
}
.box2 p
{
width: 100px;
background-color: pink;
}
p
{
float: left;
}
.wall
{
clear: both;
}
.h20{
height: 20px;
background-color: skyblue;
}
</style>
</head>
<body>
<!--3.内墙法
3.1在第一个盒子中所有子元素最后添加一个额外的块级元素
3.2给这个额外添加的块级元素设置clear: both;属性
注意点:
内墙法它可以让第二个盒子使用margin-top属性
内墙法它可以让第一个盒子使用margin-bottom属性
4.外墙法和内墙法区别?
外墙法不能撑起第一个盒子的高度, 而内墙法可以撑起第一个盒子的高度
5.在企业开发中不常用隔墙法来清除浮动
-->
<div class="box1">
<p>我是文字1</p>
<p>我是文字1</p>
<p>我是文字1</p>
<div class="wall h20"></div>
</div>
<div class="box2">
<p>我是文字1</p>
<p>我是文字1</p>
<p>我是文字1</p>
</div>
</body>
</html>