当前位置:网站首页>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 .
边栏推荐
- PowerShell cs-utf-16le code goes online
- @What happens if bean and @component are used on the same class?
- Static vxlan configuration
- ENSP MPLS layer 3 dedicated line
- 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刷题:二叉树22(二叉搜索树的最小绝对差)
- The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
- 数据库系统原理与应用教程(010)—— 概念模型与数据模型练习题
- 对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景
- leetcode刷题:二叉树26(二叉搜索树中的插入操作)
猜你喜欢
解决 Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
【统计学习方法】学习笔记——支持向量机(下)
Several methods of checking JS to judge empty objects
idm服务器响应显示您没有权限下载解决教程
解密GD32 MCU产品家族,开发板该怎么选?
Xiaohongshu microservice framework and governance and other cloud native business architecture evolution cases
数据库系统原理与应用教程(007)—— 数据库相关概念
PowerShell cs-utf-16le code goes online
Tutorial on principles and applications of database system (007) -- related concepts of database
<No. 9> 1805. Number of different integers in the string (simple)
随机推荐
密码学系列之:在线证书状态协议OCSP详解
解密GD32 MCU产品家族,开发板该怎么选?
《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
Solutions to cross domain problems
Apache installation problem: configure: error: APR not found Please read the documentation
leetcode刷题:二叉树20(二叉搜索树中的搜索)
金融数据获取(三)当爬虫遇上要鼠标滚轮滚动才会刷新数据的网页(保姆级教程)
免备案服务器会影响网站排名和权重吗?
Sign up now | oar hacker marathon phase III midsummer debut, waiting for you to challenge
JS to convert array to tree data
全球首堆“玲龙一号”反应堆厂房钢制安全壳上部筒体吊装成功
Vxlan static centralized gateway
"Series after reading" my God! It's so simple to understand throttling and anti shake~
Niuke website
Inverted index of ES underlying principle
数据库系统原理与应用教程(007)—— 数据库相关概念
【二叉树】删点成林
【PyTorch实战】图像描述——让神经网络看图讲故事
File upload vulnerability - upload labs (1~2)
About web content security policy directive some test cases specified through meta elements