当前位置:网站首页>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 .
边栏推荐
- idea 2021中文乱码
- Tutorial on the principle and application of database system (011) -- relational database
- <No. 9> 1805. Number of different integers in the string (simple)
- Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
- 牛客网刷题网址
- SQL injection -- Audit of PHP source code (take SQL lab 1~15 as an example) (super detailed)
- Niuke website
- 【统计学习方法】学习笔记——第五章:决策树
- 【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
- Using stack to convert binary to decimal
猜你喜欢

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)

AirServer自动接收多画面投屏或者跨设备投屏

The road to success in R & D efficiency of 1000 person Internet companies

Inverted index of ES underlying principle

leetcode刷题:二叉树26(二叉搜索树中的插入操作)

Tutorial on principles and applications of database system (009) -- conceptual model and data model

Several methods of checking JS to judge empty objects

BGP third experiment report

"Series after reading" my God! It's so simple to understand throttling and anti shake~

SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)
随机推荐
2022危险化学品生产单位安全生产管理人员考题及在线模拟考试
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer
平安证券手机行开户安全吗?
Is it safe to open an account in Ping An Securities mobile bank?
Typescript interface inheritance
数据库系统原理与应用教程(007)—— 数据库相关概念
【PyTorch实战】用RNN写诗
Will the filing free server affect the ranking and weight of the website?
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
<No. 9> 1805. Number of different integers in the string (simple)
跨域问题解决方案
Niuke website
【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
H3C HCl MPLS layer 2 dedicated line experiment
金融数据获取(三)当爬虫遇上要鼠标滚轮滚动才会刷新数据的网页(保姆级教程)
RHSA first day operation
SQL Lab (46~53) (continuous update later) order by injection
Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
JS to convert array to tree data
数据库系统原理与应用教程(011)—— 关系数据库