#box1_1_1 {
border: 10px dashed red;
width: 200px;
height: 100px;
}
#box1_1_2 {
border: 5px solid blue;
width: 160px;
height: 80px;
float: left;
}
#box1_2_1 {
float: left;
border: 5px solid blue;
width: 160px;
height: 80px;
z-index: 1;
/* z-index无法解决float带来的元素遮盖问题 */
}
#box1_2_2 {
border: 10px dashed red;
width: 200px;
height: 100px;
z-index: 2;
}
#box1_3_1 {
width: 200px;
height: 100px;
float: left;
border: 5px solid blue;
}
#box1_3_2 {
width: 200px;
height: 100px;
float: left;
border: 5px dashed green;
}
#box1_3_3 {
clear: both;
/* 用来清除浮动 */
}
#box1_4_1 {
float: left;
border: 5px solid blue;
}
#box1_4_2 {
float: left;
border: 5px dashed green;
}
#box1_4_3 {
clear: both;
/* 用来清除浮动 */
}
#box2_1_1 {
float: left;
width: 250px;
height: 200px;
border: 5px solid blue;
}
#box2_1_2 {
width: 300px;
height: 100px;
border: 10px dashed red;
}
#box2_1_3 {
float: left;
width: 250px;
height: 200px;
border: 5px solid blue;
}
/* 在float元素后添加一个空的block元素(必须是块级元素),并设置clear属性 */
#box2_1_3_ {
clear: both;
}
#box2_1_4 {
width: 300px;
height: 100px;
border: 10px dashed red;
}
#box2_2_1 {
float: left;
width: 250px;
height: 200px;
border: 5px solid blue;
}
#box2_2_2 {
width: 300px;
height: 100px;
border: 10px dashed red;
}
#box2_2_1 {
float: left;
width: 250px;
height: 200px;
border: 5px solid blue;
}
#box2_2_2 {
width: 300px;
height: 100px;
border: 10px dashed red;
}
#border2_2::after {
content: '';
display: block;
/* 只能为block,不能为inline-block */
clear: both;
}
#box2_3_1 {
float: left;
width: 250px;
height: 200px;
border: 5px solid blue;
}
#box2_3_2 {
width: 300px;
height: 100px;
border: 10px dashed red;
}
#box2_3_3 {
float: left;
width: 250px;
height: 200px;
border: 5px solid blue;
}
#box2_3_4 {
width: 300px;
height: 100px;
border: 10px dashed red;
}
#border2_3 {
overflow: auto;
}
/* 触发BFC有多种方式:
(1)设置overflow属性为auto/sroll/hidden之一,
(2)设置position为fixed/absolute之一,
(3)设置为float,
(4)设置display为inline-block/flex/grid之一 */
#box2_4_3 {
float: left;
width: 250px;
height: 200px;
border: 5px solid blue;
}
#box2_4_4 {
width: 300px;
height: 100px;
border: 10px dashed red;
overflow: auto;
}