CSS float(浮动)塌陷与clearfix(清除float属性)案例

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.head{
width: 100%;
border:1px solid red;
}
.head .head1{
width: 500px;
height: 100px;

float: left;
}
.head .head2{
width: 500px;
height: 100px;
background-color: blue;
float: right;
}
.content{
width: 100%;
height: 500px;
background-color: lightpink;
}
/*clearfix属性默认清楚功能 aftet追加内容*/
.clearfix:after{
/*#设置块标签*/
display: block;
/*#清除左右浮动*/
clear: both;
/*#追加内容空*/
content: ""
}

</style>
</head>
<body>

<div class="head clearfix">搜索框
<div class="head1">左搜索框部分</div>
<div class="head2">右搜索框部分</div>
</div>
<div class="content">主页内容</div>

</body>
</html>

 

posted @ 2022-05-28 21:19  呼长喜  阅读(39)  评论(0编辑  收藏  举报