Slide 1

Slide 1 text

What about CSS? Ire Aderinokun | Voxxed Days Zurich 2017 Progressive Enhancement & CSS

Slide 2

Slide 2 text

Ireoluwa Akanke Elizabeth Oluwasore Aderinokun

Slide 3

Slide 3 text

Ire

Slide 4

Slide 4 text

Rey

Slide 5

Slide 5 text

Lagos, Nigeria

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

User Interface Designer & Frontend Developer

Slide 8

Slide 8 text

Writer, bitsofco.de

Slide 9

Slide 9 text

Google Expert, Web Technologies

Slide 10

Slide 10 text

Progressive Enhancement & CSS

Slide 11

Slide 11 text

What is Progressive Enhancement?

Slide 12

Slide 12 text

Let’s go back to 2003

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

The Sound of the Internet

Slide 15

Slide 15 text

The State of the Web

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Graceful Degradation

Slide 18

Slide 18 text

The practice of building your web functionality so that it provides a certain level of user experience in more modern browsers, but it will also degrade gracefully to a lower level of user experience in older browsers.

Slide 19

Slide 19 text

HTML Your browser sucks so this feature won’t work for you. Go download Chrome.

Slide 20

Slide 20 text

March 11 2003

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Stephen Champeon Progressive Enhancement

Slide 23

Slide 23 text

The Problems with Graceful Degradation • “Doesn’t straddle technology inflection points well” • “Many designers don’t test anything but one version back” • “Does not address different needs of different audiences” • “It’s expensive to retrofit to new alternate devices” • “Whatever is ‘good enough’ usually rules” http://hesketh.com/publications/inclusive_web_design_for_the_future/

Slide 24

Slide 24 text

Enter “ Progressive Enhancement ”

Slide 25

Slide 25 text

“ Web design must mature and accept the developments of the past several years ” — Stephen Champeon

Slide 26

Slide 26 text

“ The goal of Web design is not merely to dazzle, but to deliver information to the widest audience ” — Stephen Champeon

Slide 27

Slide 27 text

Okay, but what does this actually mean in practice?

Slide 28

Slide 28 text

5 “Guidelines” for Progressive Enhancement

Slide 29

Slide 29 text

Basic content and functionality should be accessible to all web browsers

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Sparse, semantic markup should contain all content

Slide 32

Slide 32 text

HTML

Clinics 'R Us

Find a clinic near you

Where are you? Search or use current location ...

Slide 33

Slide 33 text

Content Should be Defined in Plain Text in the Markup

Slide 34

Slide 34 text

Enhanced layout can be provided by CSS stylesheets

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Enhanced behaviour can be provided by unobtrusive JavaScript

Slide 37

Slide 37 text

Search without JavaScript

Slide 38

Slide 38 text

Search with JavaScript

Slide 39

Slide 39 text

End-User web browser preferences should be respected

Slide 40

Slide 40 text

HTML

Slide 41

Slide 41 text

Why is Progressive Enhancement Important Today?

Slide 42

Slide 42 text

The world in 2016 is very different…

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

More Browsers 7% 4% 5% 6% 7% 8% 14% 50% http://gs.statcounter.com/#all-browser-ww-monthly-201608-201608-bar (other)

Slide 45

Slide 45 text

More Versions

Slide 46

Slide 46 text

More Technologies

Slide 47

Slide 47 text

More People Online 0 1,000,000,000 2,000,000,000 3,000,000,000 4,000,000,000 2003 2016 http://www.internetlivestats.com/internet-users/

Slide 48

Slide 48 text

The Web is Still Open

Slide 49

Slide 49 text

Hours Worked for 500MB of Data Number of hours worked 0 10 20 30 40 Brazil Nigeria USA Germany 1 5.7 28.2 34.4 2014 report by McKinsey & Company

Slide 50

Slide 50 text

The way you choose to build your site, matters

Slide 51

Slide 51 text

“ World Wide Web, not Wealthy Western Web ” — Bruce Lawson

Slide 52

Slide 52 text

Progressive Enhancement & JavaScript

Slide 53

Slide 53 text

What can go Wrong? • JavaScript is not enabled in the browser • The browser does not support a particular JavaScript feature

Slide 54

Slide 54 text

How do we Deal with This?

Slide 55

Slide 55 text

Make the Website Functional without JavaScript

Slide 56

Slide 56 text

JS if ( ‘serviceWorker’ in navigator ) { // Do stuff with service worker } Detect Feature Support

Slide 57

Slide 57 text

JS if ( !(’Promise’ in self ) ) { loadScript(‘promise-polyfill.js’) } Polyfill Unsupported Features

Slide 58

Slide 58 text

Simple Enough

Slide 59

Slide 59 text

Progressive Enhancement & HTML

Slide 60

Slide 60 text

What can go Wrong? • The browser does not understand the semantic meaning of an HTML element tag

Slide 61

Slide 61 text

HTML

Website Header

Lorem ipsum dolor sit amet

We Write This…

Slide 62

Slide 62 text

HTML

Website Header

Lorem ipsum dolor sit amet

…The Browser Sees This

Slide 63

Slide 63 text

How do we Deal with This?

Slide 64

Slide 64 text

HTML

Website Header

Lorem ipsum dolor sit amet

Slide 65

Slide 65 text

Simple Enough

Slide 66

Slide 66 text

So, What about CSS?

Slide 67

Slide 67 text

The Problem with Progressive Enhancement & CSS

Slide 68

Slide 68 text

CSS is a declarative language for describing presentation of a document written in markup language

Slide 69

Slide 69 text

CSS .foo { display: flex; }

Slide 70

Slide 70 text

CSS .foo { display: flex; } The Selector

Slide 71

Slide 71 text

CSS .foo { display: flex; } The Property

Slide 72

Slide 72 text

CSS .foo { display: flex; } The Value

Slide 73

Slide 73 text

What Happens if Something Goes Wrong?

Slide 74

Slide 74 text

Example

Slide 75

Slide 75 text

Desired Result

Slide 76

Slide 76 text

Result image { transform: rotate(90deg); } CSS Faulty Selector

Slide 77

Slide 77 text

Result img { transformer: rotate(90deg); } CSS Fault Property

Slide 78

Slide 78 text

Result img { transform: rotate(90degrees); } CSS Faulty Value

Slide 79

Slide 79 text

Result in Opera Mini img { transform: rotate(90deg); } CSS

Slide 80

Slide 80 text

Nothing Happens

Slide 81

Slide 81 text

Why is this a problem? • Unlike JavaScript, we can’t prepare for unsupported features • Unlike HTML, there is no “built-in” fallback

Slide 82

Slide 82 text

Debugging CSS

Slide 83

Slide 83 text

Today’s Solutions for Progressive Enhancement & CSS

Slide 84

Slide 84 text

Start with Sensible HTML

Slide 85

Slide 85 text

body { display: flex; } header { order: 1; } nav { order: 2; } main { order: 3; } footer { order: 4; } CSS HTML Don’t Do This!

Slide 86

Slide 86 text

body { display: flex; } CSS HTML Do This!

Slide 87

Slide 87 text

The Progressive Enhancement M&M http://alistapart.com/article/understandingprogressiveenhancement

Slide 88

Slide 88 text

Take Advantage of the Cascade

Slide 89

Slide 89 text

CSS div { /* Legacy styles before */ background-color: #c00; /* Modern styles after */ background-image: linear-gradient(#f00, #a00); }

Slide 90

Slide 90 text

CSS .foo { -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); } Using Vendor-Prefixed Rules

Slide 91

Slide 91 text

Go “Mobile-First”

Slide 92

Slide 92 text

When Using Media Queries, min-width > max-width

Slide 93

Slide 93 text

http://www.slideshare.net/Koombea/how-to-be-successful-with-responsive-sites-koombea-nginx-english

Slide 94

Slide 94 text

CSS /* Will work on any screen size */ .foo { width: 100%; } @media (min-width: 960px) { /* Will only work on larger screen sizes */ .foo { width: 600px; } }

Slide 95

Slide 95 text

Use Flexbox

Slide 96

Slide 96 text

Flexbox is Designed to be a Progressive Enhancement

Slide 97

Slide 97 text

CSS .center-children { text-align: center; /* Will be overridden if Flexbox is supported */ display: table-cell; vertical-align: middle; /* Flex Styles */ display: flex; justify-content: center; align-items: center; }

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

Separate Stylesheets?

Slide 100

Slide 100 text

As a last resort, create separate stylesheets

Slide 101

Slide 101 text

http://responsivenews.co.uk/post/18948466399/cutting-the-mustard

Slide 102

Slide 102 text

JS if ('querySelector' in document && 'localStorage' in window && 'addEventListener' in window) { // Bootstrap with latest features }

Slide 103

Slide 103 text

The Future of Progressive Enhancement & CSS

Slide 104

Slide 104 text

What about Feature Queries?

Slide 105

Slide 105 text

CSS Feature Queries allow authors to condition rules based on whether particular property declarations are supported by the current browser

Slide 106

Slide 106 text

CSS @supports ( /* condition */ ) { /* rules */ }

Slide 107

Slide 107 text

CSS @supports ( display: flex ) { .foo { display: flex; } } Detect if a feature is supported

Slide 108

Slide 108 text

CSS @supports ( (font-kerning: normal) and (font-feature-settings: "kern" 1) ) { .foo { font-kerning: normal; font-feature-settings: "kern" 1; } } Detect if all of several features are supported

Slide 109

Slide 109 text

CSS @supports ( (tranform: translate(-50%, -50%)) or (-webkit-tranform: translate(-50%, -50%)) ) { .foo { -webkit-tranform: translate(-50%, -50%); tranform: translate(-50%, -50%); } } Detect if either of several features are supported

Slide 110

Slide 110 text

CSS @supports not ( display: flex ) { .foo { display: table; } } Detect if a feature is not supported

Slide 111

Slide 111 text

Perfect, Isn’t it?

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

How can we use Feature Queries Today?

Slide 114

Slide 114 text

https://hacks.mozilla.org/2016/08/using-feature-queries-in-css/

Slide 115

Slide 115 text

CSS @supports ( object-fit: cover ) { img { object-fit: cover; } }

Slide 116

Slide 116 text

4 Scenarios Supports Feature Queries Does Not Support Feature Queries Supports CSS Feature Does Not Support CSS Feature

Slide 117

Slide 117 text

Supports Feature Queries & Supports CSS Feature Supports Feature Queries Does Not Support Feature Queries Supports CSS Feature Does Not Support CSS Feature

Slide 118

Slide 118 text

Supports Feature Queries & Does Not Support CSS Feature Supports Feature Queries Does Not Support Feature Queries Supports CSS Feature Does Not Support CSS Feature

Slide 119

Slide 119 text

Does Not Support Feature Queries & Does Not Support CSS Feature Supports Feature Queries Does Not Support Feature Queries Supports CSS Feature Does Not Support CSS Feature

Slide 120

Slide 120 text

Does Not Support Feature Queries & Supports CSS Feature Supports Feature Queries Does Not Support Feature Queries Supports CSS Feature Does Not Support CSS Feature

Slide 121

Slide 121 text

What’s the Solution?

Slide 122

Slide 122 text

Progressive Enhancement!

Slide 123

Slide 123 text

Use Feature Queries as a Progressive Enhancement, rather than a Requirement

Slide 124

Slide 124 text

CSS /* Fallback Code Above */ img { width: 100%; } /* Enhancement After */ @supports ( object-fit: cover ) { img { object-fit: cover; } }

Slide 125

Slide 125 text

The world in 2030?

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

More “Browsers”

Slide 128

Slide 128 text

More Technologies 123.5.2

Slide 129

Slide 129 text

More People Online

Slide 130

Slide 130 text

“ Leave no one behind ” — Stephen Champeon

Slide 131

Slide 131 text

Thank You! www.ireaderinokun.com www.bitsofco.de @IreAderinokun