• selector syntax: selector > string {property: value;}
  • colors: #RRGGBB or rgba(RRR, BBB, GGG, 0.alpha)
  • sizes: px or em (or rem)


Box Model

  • content
  • padding
  • border
  • margin

“Russian Dolls”

Display: Block vs. Inline

  • block elements have their own boxes
  • inline elements do not have boxes. height, width, padding, work inconsistently.
  • inline-block elements don’t make “true” boxes but allow you to set height and width.

Normal Flow

  • page processed sequentially
  • each block-level element gets its own line
  • inline elements displayed inside those lines
  • heights of lines set by height of content

Layout: Overriding “normal” flows

  • instruct elements to either step out of the normal flow or set new rues for their “internal” or “external” flow

Layout Methods

  • display property
  • position property
  • float property

We focus on display but dip into the other methods


values we care about:

  • display: none
  • display: block/inline/inline-block
  • display: flex
  • display: grid

Follow Along

Display: None

hide element completely so that it takes up no space at all

Display: Flex

  • one-dimensional layout
  • “content-out”
    • container determines direction & a few defaults
    • most styling still in children
  • revolutionary!

Flex Concepts: Container and Items

  • the container has display: flex;
  • the items are direct children of the container
  • container controls direction and wrapping behaviour, as well as default box alignments;
  • items control most other properties

Flex Concepts: Direction (container!)

  • main axis: horizontal if flex-direction: column; vertical if flex-direction: row
  • cross axis: vertical if flex-direction: column; horizontal if flex-direction: row

Flex Concepts: Alignment, Justification (container and items!)

  • align-items: default cross-axis alignment (stretch, flex-start, flex-end)
  • justify-content: default main-axis alignment (flex-start, flex-end, space-around, space-between)
  • align-self: item cross-axis
  • order: placement in flex-container (relative, not absolute!!)

Display: Grid

  • two-dimensional layout
  • “container-in”
    • container determines almost all layout properties
    • children choose their position within the grid
  • revolutionary!

A lot like flex!

  • many ideas come from flex
  • finer control
  • 2 dimensions, not one

Grid Concepts: Container and Items

  • as in flex

Grid Concepts: Templates and Areas (container)

  • set patterns for the 2-d grid
  • grid-template-columns: how many columns, and what size?
  • grid-template-rows: how many rows, and what size?
  • grid-template-areas: names the areas, and allows items to set their own areas

Placing Items

  • grid-column: n/m: place items by column-number
  • grid-row: n/m: place items by row-number
    • (note how these allow spanning)
  • grid-area: area-name: place by named area
    • does not allow spanning

Media Queries

  • CSS rules that only come into effect under certain conditions
  • we will only use for screen size
  • allows creation of responsive sites
@media screen and (min-width: 500px;) {
    normal.selector > here {
        normal-rule: normal-value;

@media screen and (max-width: 499px) {
    normal.selector > here {
        normal-rule: normal-value;