According to resources from W3C and MDN, a block formatting context is generated by various factors:
- The root element or its containing element
- Elements with floats (where float is not set to none)
- Absolutely positioned elements (with position set to absolute or fixed)
- Inline-block elements (display property set to inline-block)
- Table cells (set with display: table-cell, default for HTML table cells)
- Table captions (display: table-caption, default for HTML table captions)
- Elements with overflow other than visible
- Flex boxes (display set to flex or inline-flex)
However, a confusion arises in the following code snippet:
<div style='background:grey;border:black 1px dotted;width:400px'>
<div style='margin:20px;background:red;'>the parent create a bfc</div>
</div>
<div style='background:grey;width:400px'>
<div style='margin:20px;background:red;'>why?</div>
</div>
The first div establishes a BFC, even though the only variance between them is the presence of a border on the first div. This raises the question of why that specific element created a BFC.