What are the various clearing techniques and which is appropriate for what context?
Quiz · CSS
Medium
3 min
css
- Empty
divmethod -<div style="clear:both;"></div>. - Clearfix method - Refer to the
.clearfixclass above. overflow: autooroverflow: hiddenmethod - Parent will establish a new block formatting context and expand to contain its floated children.
In large projects, I would write a utility .clearfix class and use them in places where I need it. overflow: hidden might clip children if the children is taller than the parent and is not very ideal.
Adapted from the Front End Interview Handbook by Yangshun Tay and contributors (MIT License). Source
Spotted a mistake or a rights concern? Report an issue