liveBook · Manning

Proportion

As explained in Web Design Playground, Second Edition

A CSS percentage is a relative numeric value resolved against a context-dependent reference dimension.

A CSS percentage is a relative measurement: its size depends on a reference, rather than a fixed number of pixels. For an element’s width, that reference is its parent’s width—not necessarily the whole browser window. section 14.3 section 7.6

Seventy-five percent of what?

Suppose a parent is 800 pixels wide and its child has `width: 75%`. The child is 600 pixels wide, even if the browser window is 2,000 pixels wide. Want to size it relative to the window instead? Use a viewport unit. section 14.3

Percentages are handy for a liquid layout: widths and other horizontal measurements can change as the available space changes. That helps a page fit different screens without relying on fixed pixel widths. But fitting is not the same as being readable; columns can still become too narrow on a phone. section 14.12 section 14.3

A few practical choices:

  • Try percentages for horizontal widths, padding, and margins; use rem units when those spaces need tighter control. Percentage padding or margins can produce surprising results because they relate to the parent’s width. section 14.11
  • Use rem units for vertical spacing. For a layout that needs to change its arrangement at different screen sizes, add media queries; percentages alone will not fix cramped columns. section 14.11 section 14.12
.container {
    max-width: 60rem;        #1
}
header {
    padding: 1rem 1.67%;     #2#3
      
}
h1 {
    padding-left: 1.67%;     #3
}
.quotation {
    padding-right: 1.67%;    #3
}
article {
    flex-basis: 20rem;      
    padding-top: 1rem;      
    padding-left: 1.67%;      
}
p {
    margin-bottom: 1rem;      
}
aside {
    flex-basis: 10rem;     
    padding: 1rem 1.67%;      
}
div {
    padding-bottom: .5rem;      
}
footer {
    padding: 1rem 1.67%;      
}

See percentages used for horizontal padding alongside rem units for vertical spacing and controlled widths. section 14.11

How Web Design Playground, Second Edition covers it

How deep it goes
Works through parent-relative width with numbers and gives spacing guidelines, but does not develop percentage-height resolution rules.
Examples
Uses an 800-pixel parent with a 75% child width and a responsive CSS listing that mixes percentage padding with rem spacing.
What it assumes
Introduces relative widths by contrasting them with fixed pixel widths; assumes only basic familiarity with CSS properties and parent elements.
What you can do after
Apply it via CSS percentage widths and horizontal spacing, then recognize when cramped columns or surprising spacing call for another approach.
How it connects
Connects percentages to liquid layouts, CSS Grid fractional units, viewport units, rem units, and media queries.

Also explained in

Compare how 4 books explain proportion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.