BFC (Block Formatting Context) is a part of the visual CSS rendering of a web page. It is the area where the layout of block boxes occurs and where floating elements interact with other elements. It is a rendering area used for laying out block-level boxes and is completely independent of the outside area. It is a separate environment.
<!DOCTYPEhtml><html><head><title>Avoiding Float Overflow</title><styletype="text/css">.parent{border: 1px solid #eee;}.child{float: left;width: 100px;height: 300px;background-color: red;}</style></head><body><!-- Without using BFC --><!-- Floating element overflows the parent container --><divclass="parent"><divclass="child"></div></div><!-- Clearing the float, separating the example --><divstyle="clear: both;height: 20px;"></div><!-- Using display: flex; to trigger BFC --><!-- Floating elements are contained within the parent container --><divclass="parent"style="display: flex;"><divclass="child"></div></div></body></html>
<!DOCTYPEhtml><html><head><title>Avoid Text Wrapping Around Floats</title><styletype="text/css">.parent{border: 1px solid #eee;}.child{float: left;width: 100px;height: 100px;background-color: red;}</style></head><body><!-- Not using BFC --><!-- Text wraps around the child elements --><divclass="parent"><divclass="child"></div><div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div></div></div><!-- Clear floats - Separator --><divstyle="clear: both;height: 20px;"></div>```html
<!-- Trigger BFC using display: inline-block; --><!-- Text does not wrap around child elements --><divclass="parent"><divclass="child"></div><divstyle="display: inline-block;"><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div><div>1</div></div></div></body></html>