Slide 1

Slide 1 text

What about CSS? Ire Aderinokun | Fronteers Conference 2016 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

User Interface Designer & Front-End Developer

Slide 7

Slide 7 text

Writer, bitsofco.de

Slide 8

Slide 8 text

Google Developer Expert, Web Technologies

Slide 9

Slide 9 text

Progressive Enhancement & CSS

Slide 10

Slide 10 text

What is Progressive Enhancement?

Slide 11

Slide 11 text

Let’s go back to 2003

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

The Sound of the Internet

Slide 14

Slide 14 text

The State of the Web

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Graceful Degradation

Slide 17

Slide 17 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 18

Slide 18 text

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

Slide 19

Slide 19 text

March 11 2003

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Stephen Champeon “Inclusive Web Design for the Future” at SXSW

Slide 22

Slide 22 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 23

Slide 23 text

Enter “ Progressive Enhancement ”

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

Okay, but what does this actually mean in practice?

Slide 27

Slide 27 text

5 “Guidelines” for Progressive Enhancement

Slide 28

Slide 28 text

Basic content and functionality should be accessible to all web browsers

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Sparse, semantic markup should contain all content

Slide 31

Slide 31 text

HTML

Clinics 'R Us

Find a clinic near you

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

Slide 32

Slide 32 text

Content Should be Defined in Plain Text in the Markup

Slide 33

Slide 33 text

Enhanced layout can be provided by CSS stylesheets

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Enhanced behaviour can be provided by unobtrusive JavaScript

Slide 36

Slide 36 text

Search without JavaScript

Slide 37

Slide 37 text

Search with JavaScript

Slide 38

Slide 38 text

End-User web browser preferences should be respected

Slide 39

Slide 39 text

HTML

Slide 40

Slide 40 text

Why is Progressive Enhancement Important Today?

Slide 41

Slide 41 text

The world in 2016 is very different…

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

More Versions

Slide 45

Slide 45 text

More Technologies

Slide 46

Slide 46 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 47

Slide 47 text

The Web is Still Open

Slide 48

Slide 48 text

Progressive Enhancement & JavaScript

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

How do we Deal with This?

Slide 51

Slide 51 text

Make the Website Functional without JavaScript

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

Simple Enough

Slide 55

Slide 55 text

Progressive Enhancement & HTML

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

HTML

Website Header

Lorem ipsum dolor sit amet

We Write This…

Slide 58

Slide 58 text

HTML

Website Header

Lorem ipsum dolor sit amet

The Browser Sees This

Slide 59

Slide 59 text

How do we Deal with This?

Slide 60

Slide 60 text

HTML

Website Header

Lorem ipsum dolor sit amet

Slide 61

Slide 61 text

Simple Enough

Slide 62

Slide 62 text

So, What about CSS?

Slide 63

Slide 63 text

The Problem with Progressive Enhancement & CSS

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

CSS .foo { display: flex; }

Slide 66

Slide 66 text

CSS .foo { display: flex; } The Selector

Slide 67

Slide 67 text

CSS .foo { display: flex; } The Property

Slide 68

Slide 68 text

CSS .foo { display: flex; } The Value

Slide 69

Slide 69 text

What Happens if Something Goes Wrong?

Slide 70

Slide 70 text

Example

Slide 71

Slide 71 text

Desired Result

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

Nothing Happens

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

Debugging CSS

Slide 79

Slide 79 text

Today’s Solutions for Progressive Enhancement & CSS

Slide 80

Slide 80 text

Start with Sensible HTML

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

Take Advantage of the Cascade

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

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

Slide 87

Slide 87 text

Go “Mobile-First”

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

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

Slide 90

Slide 90 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 91

Slide 91 text

Use Flexbox

Slide 92

Slide 92 text

Flexbox is Designed to be a Progressive Enhancement

Slide 93

Slide 93 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 94

Slide 94 text

No content

Slide 95

Slide 95 text

Separate Stylesheets?

Slide 96

Slide 96 text

As a last resort, create separate stylesheets

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

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

Slide 99

Slide 99 text

The Future of Progressive Enhancement & CSS

Slide 100

Slide 100 text

What about Feature Queries?

Slide 101

Slide 101 text

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

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

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

Slide 104

Slide 104 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 105

Slide 105 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 106

Slide 106 text

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

Slide 107

Slide 107 text

Perfect, Isn’t it?

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

How can we use Feature Queries Today?

Slide 110

Slide 110 text

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

Slide 111

Slide 111 text

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

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

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

Slide 114

Slide 114 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 115

Slide 115 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 116

Slide 116 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 117

Slide 117 text

What’s the Solution?

Slide 118

Slide 118 text

Progressive Enhancement!

Slide 119

Slide 119 text

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

Slide 120

Slide 120 text

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

Slide 121

Slide 121 text

The world in 2030?

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

More “Browsers”

Slide 124

Slide 124 text

More Technologies 23.0

Slide 125

Slide 125 text

More People Online

Slide 126

Slide 126 text

“ Leave no one behind ” — Stephen Champeon

Slide 127

Slide 127 text

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