Hi! Today I will discuss different types of collapsing in CSS, and how to fix them.
Collapsed element is an element with a zero height.
1- Floating Elements Collapse.
2- Margin Collapse.
3- Absolute Positioning Collapse.
4- Empty Div Collapse.
This is a common problem with floated elements.
If we have an element, that contains nothing but floated elements, then this parent element will collapse.
We will apply the famous “clear-fix” to fix this problem.
It’s a fix applied to the after pseudo-element of the parent element.
Margin collapse happens when you set margin-top for an element, and margin-bottom for the element above it, then the total margin between the two elements is the max-margin between both of them, not the sum of the two margins.
To eliminate that effect, set one of the two elements' display to be inline-block.
This type of collapsing happens if the parent container that holds the absolute elements doesn't have an explicit height or width, it will collapse.
The solution is to give the parent container an explicit height or width.
Note: When you gave it a height, don't use percentages, as the parent of this parent (body) is not specified explicitly.
If we have an empty div, with no content, then it will collapse.
We could insert some content in the div, by writing the HTML special entity   that corresponds to space.
Another solution is to set a min-height, or a height (with no percentages) for the div.
That's it for today! I hope you learned from it. Good luck!