Flow and Positioning

See how a browser lays out a page before you change anything (normal flow and display), then move things on purpose with relative, absolute, fixed and sticky positioning, and decide what sits on top with z-index.

Updated

Normal Flow

  1. Normal Flow and the display Property (Apprentice): Before you move anything, the browser already lays out every page by the same rules, blocks stacking like bricks and inline boxes flowing like words, and the display and overflow properties let you change how a box takes part.
  2. Wrapping Text Around a Picture: float and clear (Apprentice): Wrap a story's words around a photo with float, keep a float from hanging out of its card with clear and display flow-root, and tell a float apart from an absolutely positioned box.

Lists and Collections

  1. Lists Hold Collections: ul, ol and What the Browser Adds (Apprentice): Menus, pet cards, tags and steps are collections of similar things, and writing them as a ul or an ol tells a screen reader how many there are, while the browser adds bullets, an indent and margins you can find in the developer tools.
  2. Styling a List That Stays a List (Apprentice): When a list should still look like a list, list-style-type, list-style-position, the list-style shorthand and ::marker change its bullets and numbers, and a few spacing rules make long and nested lists comfortable to read.
  3. Lists as Containers: Strip the Defaults, Style the Items (Apprentice): Many lists shouldn't look like lists at all, so you strip one list's bullets, indent and margins with three declarations on its class, then style each li as a box, such as a card or a menu row with a link that fills it.
  4. Lists Side by Side, by Hand (Apprentice): A menu across the top of a page and a row of tag pills are lists whose items sit side by side, and display inline-block does it by hand, with the gap the HTML's spaces add, vertical-align and text-align to line the row up, and wrapping that comes free.

Exercise: The Adoption List, Restyled

  1. Exercise: The Adoption List, Restyled (Apprentice): Turn every list on Paws & Whiskers' Meet the pets page into what it should look like, a menu of buttons in a row, the pets as cards, their tags as pills and the adoption steps as big red numbers, and wrap the introduction around a photo, while the tests check each list stays a list.

Tables for Data

  1. Tables for Data: Rows, Columns and Styling Them (Apprentice): When data has rows and columns that mean something, such as prices, opening hours or high scores, a table holds it, so you write it with caption, thead, tbody, th and td, then make it readable with border-collapse, padding, aligned numbers, stripes and a box that scrolls on a phone.

Positioning

  1. Positioning: relative and absolute (Apprentice): Nudge an element from its normal place with position relative, and pin one to a corner of its parent with position absolute, the pattern behind every badge, close button and photo caption on the web.
  2. Positioning: fixed and sticky (Apprentice): Keep a "chat with us" button on screen with position fixed, keep a header or a table's headings in reach with position sticky, and choose the right one of the five position values for any part of a page.
  3. Stacking: z-index and What Sits on Top (Journeyman): When boxes overlap, the browser stacks them like papers on a desk, and z-index, positioning and stacking contexts decide which one ends up on top, including why z-index 9999 sometimes still loses.

Exercise: Badges and a Sticky Header

  1. Exercise: Badges and a Sticky Header (Apprentice): Pin New! badges to the corners of Paws & Whiskers' pet cards, lay an overlay over a photo, make the header stick and the Adopt today button stay on screen, and choose what sits in front, while the tests check every rule.