当前位置:网站首页>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;}
边栏推荐
- 增加对 Textbundle 的支持
- C语言之自定义类型------结构体
- 图解LeetCode——640. 求解方程(难度:中等)
- ①In-depth analysis of CAS SSO single sign-on framework source code
- Google search skills - programmer is recommended
- What does the sanction of the mixer Tornado mean for the DeFi market?
- 面试常考的7种排序算法
- A practice arrangement about map GIS (below) GIS practice of Redis
- 荣威imax8ev魔方电池安全感,背后隐藏着哪些黑化膨胀?
- AI+Medical: Using Neural Networks for Medical Image Recognition and Analysis
猜你喜欢
Deep Learning - Second Time
flink The object probably contains or references non serializable fields.
DOM-DOM tree, a DOM tree has three types of nodes
高校就业管理系统设计与实现
ES6进阶 字符串处理新特性
互换性与测量技术——表面粗糙度选取和标注方法
How does MSP430 download programs to the board?(IAR MSPFET CCS)
Qnet弱网测试工具操作指南
[idea error] Invalid target distribution: 17 solution reference
①In-depth analysis of CAS SSO single sign-on framework source code
随机推荐
调试技巧总结
oracle的基数会影响到查询速度吗?
Detailed explanation of new features of ES advanced function syntax
【愚公系列】2022年08月 Go教学课程 036-类型断言
互换性与测量技术——表面粗糙度选取和标注方法
广州纸质发票再见!开住宿费电子发票即将全面取代酒店餐饮加油站发票
"Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising
The ifconfig compared with IP command
leetcode:358. K 距离间隔重排字符串
【愚公系列】2022年08月 Go教学课程 035-接口和继承和转换与空接口
荣威imax8ev魔方电池安全感,背后隐藏着哪些黑化膨胀?
一次简单的 JVM 调优,学会拿去写到简历里
字体反扒
《人生若如初见》命运多舛,人物饱满,朱亚文角色反差太惊喜
轮转数组问题:如何实现数组“整体逆序,内部有序”?“三步转换法”妙转数组
什么是三方支付?
Add support for Textbundle
CSDN blog replacement skin
A practice arrangement about map GIS (below) GIS practice of Redis
Salesforce解散中国团队,什么样的CRM产品更适合中国人