当前位置:网站首页>The thirteenth day of learning programming
The thirteenth day of learning programming
2022-08-11 03:21:00 【May 8 same city】
Height collapse:
The height of the parent element is generally stretched by the child element or the content. If the child element is set to float, the child element will be separated from the document flow and cannot support the height of the parent element, thusCauses the height of the parent element to be lost and the page layout is chaotic
Solution 1 to solve the height collapse:
Set the height of the parent element
This method is not recommended
The implicit attribute in the page element: Block FormattingContext is the block formatting context, referred to as BFC
When the BFC of the element is turned on, the element will become an independent layout area, and will not affect the layout of the outside elements
BFC is understood as a closed big box, elements inside the box will not affect the outside.
After BFC is enabled, the element will have the following characteristics:
1. The vertical margin of the parent element will not overlap with the child element (to solve the problem of overlapping parent and child margins)
2. The element with BFC enabled does notIt will be covered by floating elements
3. Elements with BFC enabled can contain floating child elements (can solve height collapse)
How to enable BFC of elements
1. Set element floating (not recommended)
- Using this method to open, although the parent element can be stretched, it will cause the width of the parent element to be lost
And using this method will also cause the lower element to move up, which cannot solve the problem
2. SettingElement is inline-block (not recommended) - It can solve the problem of height loss, but it will cause width loss, and there will be a three-pixel blank, which is not recommended
3. Set the overflow of the element to a non-visible value
The side effects are relatively small, it is recommended to use
4. Set the absolute positioning of the element (not learned yet) The
element will also be separated from the document flow. Although it can stretch the parent element, it will cause the width of the parent element to be lost.
and useThis method will also cause the element below to move up, which cannot solve the problem.
Recommended method: Setting overflow to hidden is the way to enable BFC with the least side effect.
Sometimes we want to clear the influence of other floating elements on the current element, then we can use clear to complete the function
clear can be used to clear the influence of other floating elements on the current element
Optional value:
none, the default value, does not clear the floating
left, clears the influence of the left floating element on the current element
right, clears the influence of the right floating element on the current element
both, clears the floating elements on both sidesInfluence on the current element
Clear the float of the element that affects him the most
Solution 3 for height collapse:
You can directly add a blank block element at the end of the height collapsed parent element,
Since this block element is not floating, it can stretch the height of the parent element,
and then clear the floating, so that the height of the parent element can be stretched through this blank block element,
> Basically no side effects
Although this method can solve the problem, it will add redundant structure to the page.
When the element is set to float, it will be completely separated from the document flow, and some characteristics of the element will also be changed.
The characteristics of leaving the document flow
Block element:
1: The block element no longer occupies a single line of the page.
2: The width and height of the block element are stretched by the content
Inline elements:
1: The floated inline elements are more like inline block elements, because multiple lines can be displayed, and the default width is the content of the contentWidth
Summary: When the element is set to float and is separated from the document flow, there is no need to distinguish between block and inline
边栏推荐
- DOM-DOM树,一个DOM树有三种类型的节点
- Redis老了吗?Redis与Dragonfly性能比较
- watch监听
- “顶梁柱”滑坡、新增长极难担重任,阿里“蹲下”是为了跳更高?
- A large horse carries 2 stone of grain, a middle horse carries 1 stone of grain, and two ponies carry one stone of grain. It takes 100 horses to carry 100 stone of grain. How to distribute it?
- EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?
- 浮点数在内存中的存储方式
- What does the sanction of the mixer Tornado mean for the DeFi market?
- 聊聊对RPC的理解
- Environment configuration of ESP32 (arduino arduino2.0 VScode platform which is easy to use?)
猜你喜欢

E-commerce project - mall time-limited seckill function system

Official release丨VS Code 1.70

CSDN 博客更换皮肤

A Practical Arrangement of Map GIS Development Matters (Part 1)

A large horse carries 2 stone of grain, a middle horse carries 1 stone of grain, and two ponies carry one stone of grain. It takes 100 horses to carry 100 stone of grain. How to distribute it?

MSP430如何给板子下载程序?(IAR MSPFET CCS)

SQL 开发的十个高级概念

互换性与测量技术——表面粗糙度选取和标注方法

DNS分离解析和智能解析

浮点数在内存中的存储方式
随机推荐
【Yugong Series】August 2022 Go Teaching Course 036-Type Assertion
[BX]和loop
ES6 advanced string processing new features
js中的this问题
leetcode:358. K 距离间隔重排字符串
Traversal of DOM tree-----modify styles, select elements, create and delete nodes
The practice of alibaba data synchronization component canal
调试技巧总结
[ADI low-power 2k code] Based on ADuCM4050, ADXL363, TMP75 acceleration, temperature detection and serial port printing, buzzer playing music (lone warrior)
高度塌陷问题的解决办法
A Practical Arrangement of Map GIS Development Matters (Part 1)
浮点数在内存中的存储方式
this question in js
重庆纸质发票再见!开住宿费电子发票即将全面取代酒店餐饮加油站发票
Salesforce解散中国团队,什么样的CRM产品更适合中国人
2022-08-10 第六小组 瞒春 学习笔记
【Unity入门计划】Unity2D动画(1)-动画系统的组成及功能的使用
怎么删除语句审计日志?
言简意赅,说说 @Transactional 在项目中的使用
CTO说MySQL单表行数不要超过2000w,为啥?