What is Block Formatting Context (BFC) in CSS
Block Formatting Context (BFC) is a mini layout in the page. When an element establishes a BFC, it:
- includes internal floated elements
- exclude external floated elements
- suppresses margin collapsing
A BFC is created in many situations, see Block formatting context - CSS: Cascading Style Sheets | MDN. The simplest way to create a BFC is display: flow-root
.
Here is an example of excluding external floated elements (live preview):
|
|
|
|
Further reading:
- Block formatting context - CSS: Cascading Style Sheets | MDN
- Introduction to formatting contexts - CSS: Cascading Style Sheets | MDN