An HTML document is a living document
Even without any CSS applied, an HTML document already has its own rules:
- fluidity: how the content adapts to browser dimensions
- ordering: in which order elements appear
- stacking: how elements appear on top of each other
This natural behavior is logical.
In HTML, the content is King.
block elements are fluid. They will naturally adapt their layout to accommodate their inner content:
- width: 100%
a block will take up the whole width available
- word wrap
if a block’s inline content doesn’t fit on a single line, it will continue on a new line
- height: auto
a block’s height varies automatically to match its content’s size
blockis by default in full width
- Its height is the height of its content
HTML elements are displayed in the order in which they are written in the code. First in the code -> first in the browser.
block appears in the order in which they appear in the HTML code, from top to bottom.
A browser has 3 dimensions.
Each HTML element belongs to an imaginary layer.
The stack order depends on how elements are nested: child elements appear on top of their respective parents.
- Each nested element appears on top of its parent.
- The deeper in the hierarchy, the higher in the stack.
This nested child appears on top of its parent
Breaking the flow
While the browser’s default behavior is efficient, it may not be sufficient for your design needs.
Several CSS properties allow to disrupt the Flow:
widthcan alter an element’s fluidity
floatdisrupts an element’s behavior as well as its surroundings
fixedremove an element from the Flow
z-indexcan alter the order in which elements are stacked