当前位置:网站首页>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 .
边栏推荐
- Aike AI frontier promotion (7.7)
- Vxlan static centralized gateway
- Baidu digital person Du Xiaoxiao responded to netizens' shouts online to meet the Shanghai college entrance examination English composition
- How much does it cost to develop a small program mall?
- Introduction and application of smoothstep in unity: optimization of dissolution effect
- Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios
- 2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作
- TypeScript 接口继承
- About sqli lab less-15 using or instead of and parsing
- Static comprehensive experiment
猜你喜欢
Zhimei creative website exercise
Attack and defense world ----- summary of web knowledge points
金融数据获取(三)当爬虫遇上要鼠标滚轮滚动才会刷新数据的网页(保姆级教程)
Configure an encrypted web server
消息队列消息丢失和消息重复发送的处理策略
【深度学习】图像多标签分类任务,百度PaddleClas
普乐蛙小型5d电影设备|5d电影动感电影体验馆|VR景区影院设备
Processing strategy of message queue message loss and repeated message sending
[statistical learning methods] learning notes - improvement methods
跨域问题解决方案
随机推荐
NGUI-UILabel
密码学系列之:在线证书状态协议OCSP详解
File upload vulnerability - upload labs (1~2)
2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作
111. Network security penetration test - [privilege escalation 9] - [windows 2008 R2 kernel overflow privilege escalation]
2022聚合工艺考试题模拟考试题库及在线模拟考试
【玩转 RT-Thread】 RT-Thread Studio —— 按键控制电机正反转、蜂鸣器
Sonar:cognitive complexity
(to be deleted later) yyds, paid academic resources, please keep a low profile!
Visual studio 2019 (localdb) \mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports version 782 and earlier
BGP third experiment report
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
EPP+DIS学习之路(1)——Hello world!
Is it safe to open an account in Ping An Securities mobile bank?
The left-hand side of an assignment expression may not be an optional property access.ts(2779)
Completion report of communication software development and Application
leetcode刷题:二叉树22(二叉搜索树的最小绝对差)
Processing strategy of message queue message loss and repeated message sending
Tutorial on principles and applications of database system (010) -- exercises of conceptual model and data model
Preorder, inorder and postorder traversal of binary tree