其他分享
首页 > 其他分享> > CSS float(浮动)塌陷与clearfix(清除float属性)案例

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>

 

标签:head,clearfix,float,height,width,CSS,500px
来源: https://www.cnblogs.com/A121/p/16321993.html