当前位置:网站首页>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 .
边栏推荐
- BGP third experiment report
- Ctfhub -web SSRF summary (excluding fastcgi and redI) super detailed
- 解密GD32 MCU产品家族,开发板该怎么选?
- Cryptography series: detailed explanation of online certificate status protocol OCSP
- The IDM server response shows that you do not have permission to download the solution tutorial
- Attack and defense world - PWN learning notes
- Visual studio 2019 (localdb) \mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports version 782 and earlier
- ps链接图层的使用方法和快捷键,ps图层链接怎么做的
- BGP actual network configuration
- An error occurred when vscade tried to create a file in the target directory: access denied [resolved]
猜你喜欢
![An error occurred when vscade tried to create a file in the target directory: access denied [resolved]](/img/14/9899f5a765872fb3238be4305a2dc7.png)
An error occurred when vscade tried to create a file in the target directory: access denied [resolved]

BGP third experiment report

MPLS experiment

IPv6 experiment

idea 2021中文乱码
![[statistical learning methods] learning notes - improvement methods](/img/c5/515f171995da8e424de290228b54f8.png)
[statistical learning methods] learning notes - improvement methods

Static routing assignment of network reachable and telent connections

即刻报名|飞桨黑客马拉松第三期盛夏登场,等你挑战

leetcode刷题:二叉树19(合并二叉树)

SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
随机推荐
Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
编译 libssl 报错
Sonar:cognitive complexity
Apache installation problem: configure: error: APR not found Please read the documentation
gcc 编译报错
Tutorial on the principle and application of database system (011) -- relational database
Cryptography series: detailed explanation of online certificate status protocol OCSP
静态Vxlan 配置
[pytorch practice] image description -- let neural network read pictures and tell stories
About web content security policy directive some test cases specified through meta elements
Preorder, inorder and postorder traversal of binary tree
leetcode刷题:二叉树22(二叉搜索树的最小绝对差)
"Series after reading" my God! It's so simple to understand throttling and anti shake~
什么是ESP/MSR 分区,如何建立ESP/MSR 分区
Completion report of communication software development and Application
Sign up now | oar hacker marathon phase III midsummer debut, waiting for you to challenge
How to use PS link layer and shortcut keys, and how to do PS layer link
2022聚合工艺考试题模拟考试题库及在线模拟考试
Using stack to convert binary to decimal
免备案服务器会影响网站排名和权重吗?