BFC简介
它是一块独立的渲染区域,它规定了在该区域中,常规流块盒的布局
创建BFC
BFC渲染区域: 这个区域由某个HTML元素创建,以下元素会在其内部创建BFC区域:
-
根元素
-
浮动和绝对定位元素(包括固定定位)
-
overflow不等于visible的块盒
-
display设置为inline-block或者inline-table或flex
BFC特性
- 创建BFC的元素,它的自动高度需要计算浮动元素(可以使用该特性来解决高度坍塌问题)
<!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>Document</title>
<style>
.container{
background-color: lightblue;
}
.item{
float: left;
width: 200px;
height: 200px;
background-color: #008c8c;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="item">