I'm reading CSS2.1 spec to understand CSS's visual formatting model. The concept is confusing to me, and it seems that there are no articles explaining it more intuitively.
My point is who is responsible for establishing an initial formatting context for body
element. When two div
s are placed inside of body
, they are vertically stacked each other, as follows:
<body>
<div>1</div>
<div>2</div>
</body>
Because body
element consists of two block-level boxes and they are vertically stacked, two boxes seem to participate in a block formatting context. In this situation, the body
element acts as block container box. What is not understood to me is who establishes the block formatting context.
At first, i thought that any elements establish block/inline formatting context on its own. But after reading this below, i realized it isn't. Certainly, the body
(or div
etc) is not floats, absolutely positioned, or block containers that are not block boxes, etc:
Floats, absolutely positioned elements, block containers (such as inline-blocks, table-cells, and table-captions) that are not block boxes, and block boxes with 'overflow' other than 'visible' (except when that value has been propagated to the viewport) establish new block formatting contexts for their contents.
Update : I reported this issue in w3c/csswg-drafts.
html
element provides that. Not sure how or if it can be derived from the spec but it's mentioned over on MDN. – Ouroborushtml
provides initial formatting context. All descendant elements fromhtml
inherit and use that formatting context by default. But when i applied floats to an element, the element drops the initial formatting context and then creates new block formatting context on its own. – rosshjb