当前位置:网站首页>How to clear floating?
How to clear floating?
2022-07-05 11:57:00 【Xiongba is also】
The influence of floating is not cleared
- The internal height of parent element caused by child floating is 0
- The height of the sibling element of the parent element is 0, Other styles cannot be implemented

Code
<body>
<div class="father">
<div class="child1">child1</div>
<div class="child2">child2</div>
</div>
<div class="friend">friend</div>
</body>
.child1,.child2,.friend{
width:50px;
height:50px;
}
.child1{
float:left;
border:1px solid blue;
}
.child2{
float:left;
border:1px solid green;
}
.friend{
border:1px solid red;
}
.father{
border:1px solid black;
}
Method 1: Add... To the parent element .clearfix
Code
<body>
<div class="father clearfix">
<div class="child1">child1</div>
<div class="child2">child2</div>
</div>
<div class="friend">friend</div>
</body>
.child1,.child2,.friend{
width:50px;
height:50px;
}
.child1{
float:left;
border:1px solid blue;
}
.child2{
float:left;
border:1px solid green;
}
.friend{
border:1px solid red;
}
.father{
border:1px solid black;
}
.clearfix:after{
content: '';
display: block; /* perhaps table*/
clear: both;
}
.clearfix{
zoom: 1; /* IE compatible */
}
design sketch

Method 2: Add... To the parent element overflow:hidden
Code
<body>
<div class="father">
<div class="child1">child1</div>
<div class="child2">child2</div>
</div>
<div class="friend">friend</div>
</body>
.child1,.child2,.friend{
width:50px;
height:50px;
}
.child1{
float:left;
border:1px solid blue;
}
.child2{
float:left;
border:1px solid green;
}
.friend{
border:1px solid red;
}
.father{
border:1px solid black;
overflow:hidden
}
design sketch

边栏推荐
- 1.php的laravel创建项目
- 简单解决redis cluster中从节点读取不了数据(error) MOVED
- yolov5目標檢測神經網絡——損失函數計算原理
- 查看多台机器所有进程
- Is it difficult to apply for a job after graduation? "Hundreds of days and tens of millions" online recruitment activities to solve your problems
- 一类恒等式的应用(范德蒙德卷积与超几何函数)
- redis 集群模式原理
- Solve readobjectstart: expect {or N, but found n, error found in 1 byte of
- 15 methods in "understand series after reading" teach you to play with strings
- pytorch-softmax回归
猜你喜欢
随机推荐
【TFLite, ONNX, CoreML, TensorRT Export】
【TFLite, ONNX, CoreML, TensorRT Export】
The survey shows that traditional data security tools cannot resist blackmail software attacks in 60% of cases
pytorch-权重衰退(weight decay)和丢弃法(dropout)
【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】
yolov5目標檢測神經網絡——損失函數計算原理
Use and install RkNN toolkit Lite2 on itop-3568 development board NPU
多表操作-自关联查询
网络五连鞭
简单解决redis cluster中从节点读取不了数据(error) MOVED
Yolov5 target detection neural network -- calculation principle of loss function
汉诺塔问题思路的证明
COMSOL -- establishment of geometric model -- establishment of two-dimensional graphics
Redirection of redis cluster
2048 game logic
Unity xlua monoproxy mono proxy class
iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
【yolov5.yaml解析】
1 plug-in to handle advertisements in web pages
Solve readobjectstart: expect {or N, but found n, error found in 1 byte of