当前位置:网站首页>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>
边栏推荐
- 判断numpy array数组的维数
- Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
- easyui datagrid 获取多条选中的数据进行操作
- unity 获取网络时间
- Matlab draw short-term energy diagram
- JS delay execution window.onload
- 08 Du command
- js验证复杂密码
- Database notes (from Lao She)
- Promise me, don't write shit code after reading it..
猜你喜欢

调试stc8a8k64d4单片机485通信总结

MySQL recommendation

The principle of normal equation method and its difference from gradient descent method

SQL injection less24 (secondary injection)

30000 hair loss people, supporting an IPO

Unity installation failed: operation not allowed, MKDIR

Knowledge base tools | wechat, document center, image display page can be generated by dragging (with template, directly used)

参数解析与跳石板

Task04 | classification analysis

Development to testing: a six-year road to automation from scratch
随机推荐
09.01 depth first search
JSON字符串转化为JSON对象,获取某个key的值,判断某个key是否存在
知识库工具 | 微网站、文档中心、形象展示页拖拽即可生成(附模板,直接用)
06 cp 命令
毕业5年,从信息管理转行软件测试工程师,我的月薪终于突破了12k
LeetCode 122:买卖股票的最佳时机 II
Qt中为工程添加资源文件、给按钮添加图片
Try new functions | decrypt Doris complex data type array
[waiting and wakeup of QT multithreaded threads]
After changing the password in MySQL under win10, the problem of sudden login failure is solved
JS verify complex password
SQL injection less26 (filter spaces and comments, and use error injection without spaces)
08 Du command
Software Testing Technology: cross platform mobile UI automated testing (Part 2)
A few pictures help you clarify "China's financial institution system"
判断numpy array数组的维数
Overview of banking industry
Inventory of financial institutions
ORM同时使用不同数据源和不同命名转换
JS delay execution window.onload