7.2 The Flow

The default behavior of a webpage

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.

Fluidity

In HTML, the content is King.

All 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
A block element will fill up the whole width available, while its height will vary automatically according to the size of its content.
This element will be pushed downwards depending on the height of its predecessors.
  • A block is by default in full width
  • Its height is the height of its content

Ordering

HTML elements are displayed in the order in which they are written in the code. First in the code -> first in the browser.

Each block appears in the order in which they appear in the HTML code, from top to bottom.

<p>First</p>
<p>Second</p>
<p>Third</p>
<p>Fourth</p>
<p>Fifth</p>

First

Second

Third

Fourth

Fifth

Stacking

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.
<div>
  This parent is behind
  <p>
    This nested child appears <strong>on top</strong> of its parent
  </p>
</div>
This parent is behind

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:

  • height and width can alter an element’s fluidity
  • float disrupts an element’s behavior as well as its surroundings
  • position absolute and fixed remove an element from the Flow
  • z-index can alter the order in which elements are stacked
Back to top

CodeHub Application don't have any responsibility/authority on this page Contnet. it is uploaded by anonymous contributors, If you think it is voiliting any of T&C please issue a Take Down Request here

Close