The Evolution of Responsive Design

A presentation at Front End North in February 2020 in Sheffield, UK by Rachel Andrew

Slide 1

Slide 1

The Evolution of Responsive Design RACHEL ANDREW AT FRONT END NORTH 2020

Slide 2

Slide 2

How do we support all these different screen sizes?

Slide 3

Slide 3

Slide 4

Slide 4

Fluid Grids https://alistapart.com/article/fluidgrids/

Slide 5

Slide 5

Slide 6

Slide 6

Slide 7

Slide 7

target ÷ context = result

Slide 8

Slide 8

Flexible Images https://alistapart.com/article/fluid-images/

Slide 9

Slide 9

max-width: 100%

Slide 10

Slide 10

Media Queries How big is this viewport?

Slide 11

Slide 11

Responsive Web Design • Calculating percentages for floated layouts • Squishing images • Leaning on Media Queries

Slide 12

Slide 12

column-count: 3

Slide 13

Slide 13

Flexbox responds to the content

Slide 14

Slide 14

display: flex

Slide 15

Slide 15

display: flex

Slide 16

Slide 16

Flexbox is one-dimensional

Slide 17

Slide 17

flex-wrap: wrap

Slide 18

Slide 18

flex: 0 0 32%

Slide 19

Slide 19

What does it mean to respond to content?

Slide 20

Slide 20

flex-basis: auto max-content

Slide 21

Slide 21

flex-basis: auto Space reduced from max-content until all boxes fit

Slide 22

Slide 22

We don’t have to line everything up. Sometimes what we need is just to make things fit nicely.

Slide 23

Slide 23

CSS Grid For when you do want to line everything up.

Slide 24

Slide 24

.grid { display: grid; grid-template-columns: repeat(12, 1fr); }

Slide 25

Slide 25

repeat(12, 1fr)

Slide 26

Slide 26

.grid { display: grid; grid-template-columns: repeat(12, minmax(auto, 1fr)); }

Slide 27

Slide 27

repeat(12, 1fr)

Slide 28

Slide 28

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); }

Slide 29

Slide 29

repeat(12, minmax(0,1fr))

Slide 30

Slide 30

Responding to content in a grid layout world

Slide 31

Slide 31

auto

Slide 32

Slide 32

grid-template-columns: repeat(3, auto)

Slide 33

Slide 33

justify-content: start

Slide 34

Slide 34

repeat(12, 1fr)

Slide 35

Slide 35

flex-basis: auto repeat(3, 1fr)

Slide 36

Slide 36

min-content, max-content, fit-content Directing content-based sizing

Slide 37

Slide 37

repeat(3, min-content)

Slide 38

Slide 38

repeat(3, max-content)

Slide 39

Slide 39

repeat(3, fit-content(400px)) max-content 400px

Slide 40

Slide 40

.media { display: grid; grid-template-columns: fit-content(300px) 1fr; gap: 20px; }

Slide 41

Slide 41

Slide 42

Slide 42

Flexible images More than just max-width: 100%

Slide 43

Slide 43

Responsive Images

Slide 44

Slide 44

Solving the janky images problem Mapping HTML attributes width and height to an aspect ratio.

Slide 45

Slide 45

It’s time to start using the width and height attributes on the <img> element again

Slide 46

Slide 46

Slide 47

Slide 47

Media Queries

Slide 48

Slide 48

column-width: 200px

Slide 49

Slide 49

flex-wrap: wrap

Slide 50

Slide 50

repeat(auto-fill, minmax(200px, 1fr)

Slide 51

Slide 51

The first rule of Media Queries is … Do I need a media query?

Slide 52

Slide 52

.wrapper { display: grid; grid-template-areas: “hd” “bd” “sd” “ft”; }

Slide 53

Slide 53

Slide 54

Slide 54

@media (min-width: 600px) { .wrapper { grid-template-columns: 3fr 1fr; grid-template-areas: “hd hd” “bd sd” “ft ft”; } }

Slide 55

Slide 55

Slide 56

Slide 56

More than just screen size What else could we respond to?

Slide 57

Slide 57

What type of pointer do I have?

Slide 58

Slide 58

@media (pointer:coarse) { .pointer::before { content: “You have a coarse pointer”; } } @media (pointer:fine) { .pointer::before { content: “You have a fine pointer”; } }

Slide 59

Slide 59

Can I hover?

Slide 60

Slide 60

@media (hover) { .can-i-hover::after { content: “You look like you can hover.”; } } @media (hover:none) { .can-i-hover::after { content: “I don’t think you can hover.”; } }

Slide 61

Slide 61

@media (any-pointer:coarse) { .any-pointer::before { content: “One of your pointers is coarse. Yo ur device has a touchscreen, though you might not be using it.”; } }

Slide 62

Slide 62

Slide 63

Slide 63

“ Designing a page that relies on hovering or accurate pointing only because any-hover or anypointer indicate that at least one of the available input mechanisms has these capabilities is likely to result in a poor experience. Media Queries Level 4 https://drafts.csswg.org/mediaqueries-4/#any-input ”

Slide 64

Slide 64

Testing capabilities Check for screen size, but also pointer type and hover ability to understand the environment your site is being used in.

Slide 65

Slide 65

Overflow detection Display Quality Media Queries

Slide 66

Slide 66

@media (overflow-block: paged) { /* CSS for paged media */ }

Slide 67

Slide 67

Responding to the wishes of the visitor Media Queries Level 5 and User Preference Media Features

Slide 68

Slide 68

prefers-reduced-motion

Slide 69

Slide 69

@media (prefers-reduced-motion: reduce) { .animation { animation: none; } }

Slide 70

Slide 70

prefers-color-scheme

Slide 71

Slide 71

@media (prefers-color-scheme: dark) { body { background: #333; color: white; } }

Slide 72

Slide 72

prefers-reduced-data

Slide 73

Slide 73

@media (prefers-reduced-data: reduce) { /* CSS loading in smaller images */ }

Slide 74

Slide 74

Feature Queries What does this browser support?

Slide 75

Slide 75

@supports (display: grid) { .grid { display: grid; grid-template-columns: repeat(3, 1fr); } }

Slide 76

Slide 76

What does it mean to do responsive design today?

Slide 77

Slide 77

Respond to content

Slide 78

Slide 78

Use new layout and image features

Slide 79

Slide 79

Use media features to enhance your site.

Slide 80

Slide 80

It’s not about screen size

Slide 81

Slide 81

Responding to needs and environment

Slide 82

Slide 82

Stop expecting people to fix something to use your website. Respond to meet them where they are.

Slide 83

Slide 83

Thank you! https://noti.st/rachelandrew