Step 2.1 · Day 2: CSS design · Review + new

How CSS works

CSS (Cascading Style Sheets) controls how the HTML looks: color, type, spacing and layout at every screen size.

A colorful house: blue walls, green windows and a red door
If HTML is the structure of the house, CSS is the paint, materials and furniture.

The parts of a CSS rule

The rule h1 {color: blue; font-size: 12px;} labeled: selector, declarations, properties and values

Selectors you will use

SelectorStyles
bodythe element itself: here, the whole page
.cardevery element with class="card" (a period means “class”)
nav aevery link inside the nav (a space means “inside”)
nav a:hovera nav link while the mouse is over it
h1, h2, h3all three heading levels (a comma means “and”)

The cascade

When two rules style the same thing, the browser decides which one wins:

  1. The more specific rule wins. .card h3 beats h3.
  2. If they are equally specific, the later rule wins. This is why responsive rules go at the bottom of the file.

Units

UnitMeansUse for
pxpixelsborders, shadows, small fixed details
remmultiples of the base font size (1rem = 16px)font sizes and spacing, because they grow if a visitor enlarges their text
%a share of the parent element’s widthflexible widths
fra fraction of the free space in a gridgrid columns
Look it up

Keep the W3Schools CSS reference open while you build.

© Created by Sara Rosenstock, Marietta College Graphic Design.