当前位置:网站首页>Height collapse caused by floating
Height collapse caused by floating
2022-07-26 22:25:00 【Self cultivation record of waste】
Normal page layout
<style> *{
margin:0; padding: 0; } .content{
width:400px; border:1px solid #000; } .box{
width:200px; height:200px; background: greenyellow; } </style>
<body>
<div class="content">
<div class="box"></div>
</div>
<p> Jiku astifen </p>
</body>

When the class name is .box The box with floating
<style> *{
margin:0; padding: 0; } .content{
width:400px; border:1px solid #000; } .box{
width:200px; height:200px; background: greenyellow; float: left; } </style>

You can see that the page layout is messy , Because the element will leave the document flow after floating
Solution
1 utilize BFC( Add... To the parent element overflow:hidden)
** shortcoming : The overflow element of the parent element will be hidden , May affect the page display **
.content{
width:400px;
border:1px solid #000;
overflow: hidden;
}
2 Empty div
The main points of :
1. Add an empty block level element
2. Clear floating for block level elements , Easy way , Do not manage whether to float left or right , Directly clear all (clear:both)
<style> *{
margin:0; padding: 0; } .content{
width:400px; border:1px solid #000; /* overflow: hidden; */ } .box{
width:200px; height:200px; background: greenyellow; float: left; } .clear{
clear: both; } </style>
<body>
<div class="content">
<div class="box"></div>
<div class="clear"></div>
</div>
<p> Jiku astifen </p>
</body>
3 Using pseudo elements
The main points of :
1 In fact, and add empty div The principle is the same , The only thing to remember is to turn pseudo elements into block level elements (display:block), Otherwise it will have no effect
2 And don't forget to add the attributes of pseudo elements (content:‘’)
<style> *{
margin:0; padding: 0; } .content{
width:400px; border:1px solid #000; /* overflow: hidden; */ } .content::after{
content: ''; display: block; // Must be converted to a block element clear: both; } .box{
width:200px; height:200px; background: greenyellow; float: left; } /* .clear{ clear: both; } */ </style>
<body>
<div class="content">
<div class="box"></div>
<!-- <div class="clear"></div> -->
</div>
<p> Jiku astifen </p>
</body>
边栏推荐
- Protobuf之proto基础语法
- Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
- 【论文阅读】LOGAN:Membership Inference Attacks Against Generative Models
- JS verify complex password
- Altium designer 22 modify the layer properties of the selected component
- Matlab draw short-term energy diagram
- Matlab solution of the densest stacking and smallest circumscribed square of N circles (two-dimensional, three-dimensional, etc. circle packing problem)
- 08.02 adjacency table
- iptables防止nmap扫描以及binlog实现增量备份
- The potential of emerging markets is unlimited, and advance.ai risk control products help Chinese offshore enterprises build a solid foundation for safe development
猜你喜欢

Instructions for use of light source controller dial switch

SQL注入 Less24(二次注入)
![[horizon sunrise X3 sect trial experience] + unpacking post](/img/b1/3196b470e601dc63ce3b11a7deb3cd.png)
[horizon sunrise X3 sect trial experience] + unpacking post

30000 hair loss people, supporting an IPO

基于gRPC编写golang简单C2远控

08 Du command

Add resource files for the project and pictures for buttons in QT

leetcode:857. 雇佣 K 名工人的最低成本【分块思考 + 由简单入手】

Altium Designer 22 修改选中元件的层属性

Knowledge base tools | wechat, document center, image display page can be generated by dragging (with template, directly used)
随机推荐
JS delay execution window.onload
d和c的符区别
View绘制流程1-View与Window的关系
Altium Designer 22 中文字符乱码
Go -- go language naming specification
ZABBIX calls API retrieval method
09 expr command
shell相关命令总结
09 expr 命令
iptables防止nmap扫描以及binlog实现增量备份
ORM同时使用不同数据源和不同命名转换
SQL注入 Less26(过滤空格和注释符,使用不带空格的报错注入)
Unity对资源管理器操作 打开资源管理器选择文件并筛选文件
[horizon sunrise X3 sect trial experience] + unpacking post
Luo Yonghao bet on the last entrepreneurial credit
Regular expressions and bypass cases
At the 100 billion yogurt track, dairy giants and new brands have started a tug of war
js验证复杂密码
博客园美化技巧汇总
unity 获取网络时间