当前位置:网站首页>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 .
边栏推荐
- @What happens if bean and @component are used on the same class?
- 平安证券手机行开户安全吗?
- Attack and defense world ----- summary of web knowledge points
- SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
- Object. Simple implementation of assign()
- 静态Vxlan 配置
- H3C HCl MPLS layer 2 dedicated line experiment
- 什么是ESP/MSR 分区,如何建立ESP/MSR 分区
- Completion report of communication software development and Application
- 数据库系统原理与应用教程(008)—— 数据库相关概念练习题
猜你喜欢
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer
数据库系统原理与应用教程(011)—— 关系数据库
SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
Vxlan 静态集中网关
EPP+DIS学习之路(1)——Hello world!
2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试
Tutorial on principles and applications of database system (007) -- related concepts of database
File upload vulnerability - upload labs (1~2)
idea 2021中文乱码
The road to success in R & D efficiency of 1000 person Internet companies
随机推荐
idm服务器响应显示您没有权限下载解决教程
[pytorch practice] image description -- let neural network read pictures and tell stories
数据库系统原理与应用教程(009)—— 概念模型与数据模型
Static routing assignment of network reachable and telent connections
idea 2021中文乱码
SQL injection -- Audit of PHP source code (take SQL lab 1~15 as an example) (super detailed)
BGP third experiment report
数据库系统原理与应用教程(007)—— 数据库相关概念
数据库安全的重要性
消息队列消息丢失和消息重复发送的处理策略
Is it safe to open Huatai's account in kainiu in 2022?
Configure an encrypted web server
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)
跨域问题解决方案
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)
【统计学习方法】学习笔记——提升方法
"Series after reading" my God! It's so simple to understand throttling and anti shake~
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer
Customize the web service configuration file