Where in the docs does it describe the normal flow for boxes that don't create a BFC
I would say in the same doc you are referring since an element that doesn't create a BFC is a box that necessarily belong to another BFC (or IFC) if it's an in-flow element.
if they don't create one, what formatting context applies?
Simpy no one. An element doesn't necessarily create a formatting context.
To make it easier to understand, let's consider the MDN definition:
A block formatting context is a part of a visual CSS rendering of a Web page. It is the region in which the layout of block boxes occurs and in which floats interact with other elements.
then we can read
Setting overflow: auto
created a new BFC containing the float. Our <div>
now becomes a mini-layout inside our layout. Any child element will be contained inside it.
In other words, a BFC is a way to isolate a part of a layout in order to avoid any interaction with the external world. Some known interactions are floating and margin collapsing.
Let's take an easy example:
.wrapper {
outline: 1px solid;
overflow: hidden;
}
.wrapper>div {
margin: 10px;
background: red;
}
<div class="wrapper">
<div>
<p>some text here</p>
<p>some text here</p>
</div>
<div>
</div>
</div>
<div class="wrapper">
<div>
</div>
</div>
In the below example we have our wrapper creating a BFC and all the elements inside belong to it including the p
tags even if they aren't direct child of it. You will notice that there is no margin collapsing with the wrapper and its child element while we have margin collapsing between the adjacent p
and between p
and the parent div
.
Let's add floating elements:
.wrapper {
outline: 1px solid;
overflow: hidden;
}
.wrapper>div {
margin: 10px;
background: red;
}
div.float {
float:left;
width:50px;
height:50px;
margin:0;
background:green;
}
<div class="wrapper">
<div class="float"></div>
<div>
<p>some text here</p>
<p>some text here</p>
</div>
<div>
</div>
</div>
<div class="wrapper">
<div class="float"></div>
<div>
</div>
</div>
Each float element belong to the BFC created by the wrapper and interact with all the elements inside it (including the p
tags).
As you can see, we have a div element that doesn't create BFC and belong to the one created by the wrapper and their child also.
Now let's make the inner div create a BFC:
.wrapper {
outline: 1px solid;
overflow: hidden;
}
.wrapper>div {
margin: 10px;
background: red;
}
div.float {
float:left;
width:50px;
height:50px;
margin:0;
background:green;
}
<div class="wrapper">
<div class="float"></div>
<div style="overflow:hidden">
<p>some text here</p>
<p>some text here</p>
</div>
<div>
</div>
</div>
<div class="wrapper">
<div class="float"></div>
<div >
</div>
</div>
You can clearly see how the float no longer behaves the same, and how the margin of p
no longer collapses with the parent div. This is because we have isolated our content and it no longer interacts with the outside world.
Now if we remove all the overflow:hidden
, we will make all the elements belong to the same BFC created by the root element (html
) and no one is creating a BFC.
.wrapper {
outline: 1px solid;
}
.wrapper>div {
margin: 10px;
background: red;
}
div.float {
float:left;
width:50px;
height:50px;
margin:0;
background:green;
}
<div class="wrapper">
<div class="float"></div>
<div >
<p>some text here</p>
</div>
<div>
</div>
</div>
<div class="wrapper">
<div class="float"></div>
<div >
</div>
</div>
We can clearly see the difference and how all the elements interact with each other epsecially the float elements.
Note that all this apply to normal flow element and to float element (with some special behavior like described in the specification) but when it comes to absolute positioning it's different.
An absolute (or fixed) element create a BFC for its content but doesn't belong to any BFC because:
It is removed from the normal flow entirely (it has no impact on later siblings)
whereas in a BFC we have:
In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block. The vertical distance between two sibling boxes is determined by the 'margin' properties