slides.oddbird.net/rws/smashing/space/

Distributing Space

slides.oddbird.net/rws/smashing/space/

@ Smashing Online

Design Unknown Content
On An Unknown Canvas

Primary Question… How Will This Change?

Since 2010 Responsive Web Design

  1. Fluid % Images
  2. Fluid % Columns
  3. @media Queries
.grid-span {
width: percentage( /* 23.7288136% */
((3 * 4em) + (2 * 1em)) / ((12 * 4em) + (11 * 1em))
);
margin-right: percentage( /* 01.6949153% */
1em / ((12 * 4em) + (11 * 1em))
);
padding-left: percentage( /* 08.4745763% */
((1 * 4em) + (1 * 1em)) / ((12 * 4em) + (11 * 1em))
);
}

CSS has Real Layout Tools

Not just Grid or Flexbox, but an entire system…

  1. Fluid & Fixed
  2. Stages of Squishiness
  3. Truly Two-Dimensional Layouts
  4. Nested Contexts
  5. Expand & Contract Content
  6. Media Queries, As Needed
  1. Fluid & Fixed
  2. Stages of Squishiness
  3. Truly Two-Dimensional Layouts
  4. Nested Contexts
  5. Expand & Contract Content
  6. Media Queries, As Needed

Reset Global Box-Sizing

*, *::before, *::after { box-sizing: border-box; }

Box Properties 👎 Shouldn’t Inherit

html { box-sizing: border-box; }
* { box-sizing: inherit; }

New… Display: Contents

Remove those pesky extra divs…

New… Display: Flow-Root

“A mini layout in your layout”…

Flow-Root Block Formatting Context

Clear floats, prevent margin-collapse…

Also… Multiple-Value Display

inline-block saw it coming…

Display-Outside Inline Flow-Root…

Behavior in parent layout

Display-Inside Inline Flow-Root

Context for child layout

Get Explicit Block Flow, Block Flex…

The default outer value, when only inner is set

Get Explicit Block Flow

The default inner value, when only outer is set

  • blockblock flow
  • flexblock flex
  • inline-flexinline flex
  • inline-blockinline flow-root

Writing Modes

horizontal-tb | vertical-rl/lr | sideways-rl/lr

Text-Orientation

mixed | upright | sideways

Understand Logical Dimensions

Writing-Mode Relative

Inline ↔ Axis Text Flow & Box Stretching

Block ↕ Axis Text Wrap & Box Stacking

Relative to… Physical Space

*-top/*-bottom/*-right/*-left

Relative to… Writing Mode

*-inline/*-block & *-start/*-end

Intrinsic Sizes

max-content | min-content | &c.

fit-content(<max>)

grid-only for now, so we’ll come back to it

Intrinsic Aspect Ratios Using Image Width/Height

to avoid layout jank

Content-Out Sharing Space

use grid for layout-in

.default-values {
flex-direction: row; // column[-reverse]
flex-wrap: nowrap; // wrap | wrap-reverse
}

Flex Items flex-grow: 1

Distribution of Available Space

Flex Items flex-shrink: 1

Distribution of Unavailable Space

Flex Items flex-basis: auto

The ideal starting width, before flexing

Four Flex Shorthand Values

initial | auto | none | <grow>

Initial Shrink, If Necessary

Same as 0 1 auto

Share Space Equally

Same as <grow> 1 0

Box Alignment

currently in flexbox & grid…

Inline Axis justify-*

justify-content | justify-items | justify-self

Block Axis align-*

align-content | align-items | align-self

Shorthand place-*

place-content | place-items | place-self

Positional Values

start | end | center

Baseline Values

baseline | first baseline | last baseline

Distributed Values

stretch | space-between | space-around | space-evenly

Real Gutters*

row-gap | column-gap | gap

Authors must use order and the grid-placement properties only for visual, not logical, reordering of content.

Grid Specification

Use ordering To Improve Readability

Always check your tab-order…

  1. Start with structured & accessible HTML
  2. Create a responsive & responsible layout
  3. If you re-order, consider updating the DOM

Viewport Relative Units

vw | vh | vmin | vmax

Responsive Type

font-size: calc(1em + 2vw)

Breaking Out

margin-inline: calc(50% - 50vw)

Replaced Elements… object-fit & object-position

object-position ~= background-position

Same values, but for placing an object

object-fit: fill

contain | cover | scale-down

Multicolumn columns: 5 10em;

column-count | column-width