当前位置:网站首页>The solution to the height collapse problem
The solution to the height collapse problem
2022-08-11 03:19:00 【Y-Joan Eye】
Today, let's take a look at a very common problem, which is the height collapse problem. I believe that many friends will encounter the height collapse problem when laying out, so today we will see how to solve it.
Height collapse
We generally do not set the height of the parent element when we set it. We usually fill it with content so that the parent element is stretched by the child element.Then there is a problem at this time. If the child element floats, the width of the parent element will collapse.In this way, our page will be cluttered, which is what we generally call the height collapse problem.
Solution for height collapse
One, set a height to the parent element
This can give the parent a height so that it won't collapse, but it's highly discouraged.
Second, enable BFC (Block Formatting Context)
When the BFC is enabled for the element, the element will become an independent area and will not affect the outside elements in the layout.
We can understand BFC as a closed big box, which can hold a lot of messy things, which does not affect the things outside.So the same element will not affect the outside elements after turning on the BFC.
Three, the third solution of height collapse (perfect)
Use the clear attribute
Add a blank div at the end of the collapsed parent element. Since this div is not floating, use the height that can stretch the parent element, and then clear and float the blank div.Not necessarily a div, other block elements can be
Basically no side effects
As shown below
.box3{clear: left;}
Fourth, the fourth solution of height collapse (perfect)
This method is based on the third method.
It is to use the pseudo-class ::after
As shown below
.box1::after{content: '';display: block;clear: both;}
边栏推荐
- Goodbye Chongqing paper invoices!The issuance of electronic invoices for accommodation expenses will soon completely replace the invoices of hotels, catering and gas stations
- ES6进阶 字符串处理新特性
- 【Unity入门计划】Unity2D动画(1)-动画系统的组成及功能的使用
- How does MSP430 download programs to the board?(IAR MSPFET CCS)
- Idea (preferred) cherry-pick operation
- 基于FPGA状态机的自动售货机功能实现
- 元素的BFC属性
- 二叉树相关代码题【较全】C语言
- C语言之自定义类型------结构体
- rac备库双节点查询到的表最后更新时间不一致
猜你喜欢
阿里低代码框架 lowcode-engine 之自定义物料篇
ES6进阶 字符串处理新特性
没想到MySQL还会问这些...
flink The object probably contains or references non serializable fields.
基于FPGA状态机的自动售货机功能实现
最倒霉与最幸运
言简意赅,说说 @Transactional 在项目中的使用
Briefly, talk about the use of @Transactional in the project
Environment configuration of ESP32 (arduino arduino2.0 VScode platform which is easy to use?)
Google search skills - programmer is recommended
随机推荐
MSP430如何给板子下载程序?(IAR MSPFET CCS)
Detailed explanation of new features of ES advanced function syntax
The 125th day of starting a business - a note
Talk about the understanding of RPC
LeetCode热题(12.买卖股票的最佳时机)
ES6 advanced string processing new features
The negative semantic transformation layer
What does the sanction of the mixer Tornado mean for the DeFi market?
Typescript学习笔记 | 字节青训营笔记
EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?
Unity2D animation (1) introduction to Unity scheme - animation system composition and the function of use
Add user error useradd: cannot open /etc/passwd
this question in js
Realization of vending machine function based on FPGA state machine
Idea (优选)cherry-pick操作
The problem that Merge will be lost again after code Revert has been solved
IDE compilation error: Dangling metacharacter
ES6进阶 字符串处理新特性
"Beijing-Taiwan high-speed rail" debuted on Baidu map, can it really be built in 2035?
成都纸质发票再见!开住宿费电子发票即将全面取代酒店餐饮加油站发票