当前位置:网站首页>Several ways to clear floating
Several ways to clear floating
2022-07-07 12:35:00 【Xiaoding Chong duck!】
Three column layout , Both use floating , Causes the parent element to collapse highly , The effect is as follows :

The code is as follows :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello</title>
</head>
<style>
.parent {
border: 3px #ffaaa7 solid;
}
.child {
height: 300px;
}
.child:nth-child(1) {
width: 200px;
float: left;
background-color: #98ddca;
}
.child:nth-child(2) {
background-color:#d5ecc2;
width: calc(100% - 400px);
float: left;
}
.child:nth-child(3) {
background-color:#ffd3b4;
width: 200px;
float: right;
}
</style>
<body>
<div class="parent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>
</body>
</html>Clear the float to achieve the effect :

One 、 Pseudo elements
It is equivalent to adding a block level element , And set up clear:both
.parent:after {
content: '';
display: block;
clear: both;
}Two 、clear
You can add clear, In this case , Because of three child Elements are floating , So add an empty one at the end div, And then add clear:both that will do
<div class="parent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
<div style="clear:both"></div>
</div>3、 ... and 、 Parent div Definition overflow:hidden
Parent element Settings overflow:hidden( except "visible" Any valid value other than ) After that, the parent element will form a BFC, and BFC The height of is the height containing the internal floating elements
.parent {
border: 3px #ffaaa7 solid;
overflow: hidden;
}In fact, all can make the parent element produce BFC Can solve the problem , But some will cause additional problems .
边栏推荐
- Is it safe to open an account in Ping An Securities mobile bank?
- IPv6 experiment
- [statistical learning methods] learning notes - improvement methods
- leetcode刷题:二叉树20(二叉搜索树中的搜索)
- wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
- SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)
- The road to success in R & D efficiency of 1000 person Internet companies
- 【PyTorch实战】图像描述——让神经网络看图讲故事
- 跨域问题解决方案
- leetcode刷题:二叉树23(二叉搜索树中的众数)
猜你喜欢

2022聚合工艺考试题模拟考试题库及在线模拟考试

In the small skin panel, use CMD to enter the MySQL command, including the MySQL error unknown variable 'secure_ file_ Priv 'solution (super detailed)

Unity map auto match material tool map auto add to shader tool shader match map tool map made by substance painter auto match shader tool

College entrance examination composition, high-frequency mention of science and Technology

IPv6 experiment

leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)

【统计学习方法】学习笔记——支持向量机(上)

leetcode刷题:二叉树22(二叉搜索树的最小绝对差)

idm服务器响应显示您没有权限下载解决教程

Attack and defense world - PWN learning notes
随机推荐
Multi row and multi column flex layout
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
Airserver automatically receives multi screen projection or cross device projection
Utiliser la pile pour convertir le binaire en décimal
How to use PS link layer and shortcut keys, and how to do PS layer link
2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试
Is it safe to open Huatai's account in kainiu in 2022?
Idea 2021 Chinese garbled code
Unity map auto match material tool map auto add to shader tool shader match map tool map made by substance painter auto match shader tool
通讯协议设计与实现
【统计学习方法】学习笔记——第五章:决策树
<No. 9> 1805. Number of different integers in the string (simple)
Ctfhub -web SSRF summary (excluding fastcgi and redI) super detailed
即刻报名|飞桨黑客马拉松第三期盛夏登场,等你挑战
盘点JS判断空对象的几大方法
@What happens if bean and @component are used on the same class?
IPv6 experiment
Aike AI frontier promotion (7.7)
In the small skin panel, use CMD to enter the MySQL command, including the MySQL error unknown variable 'secure_ file_ Priv 'solution (super detailed)
leetcode刷题:二叉树19(合并二叉树)