当前位置:网站首页>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 .
边栏推荐
- Completion report of communication software development and Application
- SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
- Tutorial on principles and applications of database system (007) -- related concepts of database
- 全球首堆“玲龙一号”反应堆厂房钢制安全壳上部筒体吊装成功
- Object. Simple implementation of assign()
- Customize the web service configuration file
- Typescript interface inheritance
- Cookie
- 牛客网刷题网址
- 【PyTorch实战】图像描述——让神经网络看图讲故事
猜你喜欢
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
Tutorial on principles and applications of database system (009) -- conceptual model and data model
leetcode刷题:二叉树27(删除二叉搜索树中的节点)
Financial data acquisition (III) when a crawler encounters a web page that needs to scroll with the mouse wheel to refresh the data (nanny level tutorial)
数据库安全的重要性
[statistical learning methods] learning notes - improvement methods
Completion report of communication software development and Application
Session
On valuation model (II): PE index II - PE band
Cookie
随机推荐
Experiment with a web server that configures its own content
【统计学习方法】学习笔记——支持向量机(上)
@What happens if bean and @component are used on the same class?
sql-lab (54-65)
The left-hand side of an assignment expression may not be an optional property access.ts(2779)
111. Network security penetration test - [privilege escalation 9] - [windows 2008 R2 kernel overflow privilege escalation]
NGUI-UILabel
Completion report of communication software development and Application
ps链接图层的使用方法和快捷键,ps图层链接怎么做的
Multi row and multi column flex layout
Cookie
leetcode刷题:二叉树23(二叉搜索树中的众数)
静态Vxlan 配置
数据库安全的重要性
Minimalist movie website
【玩转 RT-Thread】 RT-Thread Studio —— 按键控制电机正反转、蜂鸣器
Cryptography series: detailed explanation of online certificate status protocol OCSP
GCC compilation error
H3C HCl MPLS layer 2 dedicated line experiment
leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)