Slide 1
Post-Modern CSS IN-DEPTH ON GRID LAYOUT, FLEXBOX & OTHER NEW PROPERTIES
Slide 2
Wait. Post-Modern? L …A W ? IKE
NDY
ARHOL
Slide 3
Wait. Post-Modern? L …A W ?S . IKE
NDY
ARHOL
ORTA
Slide 4
“Simplifying to the extreme, I define postmodern as an incredulity toward metanarratives.”
– Jean-François Lyotard
Slide 5
“Postmodernism was a reaction to modernism. Where modernism was about objectivity, postmodernism was about subjectivity. Where modernism sought a singular truth, postmodernism sought the multiplicity of truths.” – Miguel Syjuco
Slide 6
Why Post-Modern? A VERY BRIEF HISTORY OF THE ERAS OF THE WEB AND CSS
Slide 7
Pre-History P - -P C OINT TO
OINT ONNECTIONS; BULLETIN BOARDS; RESEARCHERS
Slide 8
The Classical Era HTTP; HTML; T B ;S T HE ROWSER
IR IM BERNERS-LEE
Slide 9
The Middle Ages O R F CSS R THE
ISE AND ALL OF
Slide 10
The Modern Era HTML5; CSS3; A JS; F DVANCED
RAMEWORKS
Slide 11
Postmodernity A L ; R -E DVANCED AYOUT
E
MERGENCE OF UNIQUE DESIGN
Slide 12
“Postmodernism was a reaction to modernism. Where modernism was about objectivity, postmodernism was about subjectivity. Where modernism sought a singular truth, postmodernism sought the multiplicity of truths.” – Miguel Syjuco
Slide 13
Slide 14
SOURCE: HTTP://ADVENTUREGA.ME/BOOTSTRAP/
Slide 15
“Simplifying to the extreme, I define postmodern as an incredulity toward metanarratives.”
– Jean-François Lyotard
Slide 16
Slide 17
“CSS Sucks” -E D E VERY
EVELOPER VER
Slide 18
The Rise and Fall of CSS THE BATTLE OVER STYLE SHEETS AND IMPLEMENTATION
Slide 19
CSS Starts Strong 1994: CSS1 Spec starts 1996: CSS1 Spec complete (IE3 kinda adopts)
2000: IE5 reaches 99% CSS1 adoption
Slide 20
The middle part, not so much 1998: CSS2 Spec first WD 2000: CSS2 Becomes Recommendation
2000-07: CSS2/2.1 turmoil and back and forth
2011: CSS2.1 Finally finished and published SOURCE: HTTP://LEARNCSS.INFO/
Slide 21
Why CSS3 is better T M HE SECRET SAUCE IS
ODULES
SOURCE: MDN
Slide 22
Further Reading • •
The CSS Saga The Evolution of CSS
Slide 23
The New Hotness TODAY’S GOAL: ADOPT ONE OF THESE PROPERTIES
Slide 24
CSS Gradients WHY USE IMAGES WHEN CSS CAN DO AMAZING THINGS?
Slide 25
Slide 26
body { background-image: lineargradient(#F46035, #7E311C); }
Slide 27
body { background-image: lineargradient(45deg, #F46035, #7E311C); }
Slide 28
body { background-image: lineargradient(to bottom, #F46035, #7E311C 50%, #F46035 70%); }
Slide 29
body { background-image: radialgradient(#F46035, #7E311C); }
Slide 30
body { background-image: radialgradient(circle at 10% 0, #F46035, #7E311C 50%); }
Slide 31
body { background-image: repeatinglinear-gradient(to top right, #F46035, #F46035 20px, #7E311C 20px, #7E311C 40px); }
Slide 32
repeating-linear-gradient( [direction], [first color] #F46035, [first color again to fight fade] #F46035 20px, [second color] #7E311C 20px, [second color again to fight fade] #7E311C 40px );
Slide 33
Flexbox TRULY RESPONSIVE UNI-DIRECTIONAL LAYOUT
Slide 34
Support
(USE UNLESS <IE10 IS IMPORTANT)
Slide 35
DEFAULT: BLOCK-LEVEL
<div class=”container”> <div class=”box box1”>1</div> <div class=”box box2”>2</div> <div class=”box box3”>3</div> <div class=”box box4”>4</div> <div class=”box box5”>5</div> <div class=”box box6”>6</div> </div>
Slide 36
DEFAULT: SIMPLE STYLING .container { width: 510px; margin: 0 auto; background: lightblue; } .box { background-color: tomato; margin: 20px 0; padding: 20px; color: white; }
Slide 37
.container { width: 510px; margin: 0 auto; background: lightblue; } .box { float: left; background-color: tomato; margin: 20px 0; padding: 20px; color: white; }
Slide 38
.container:after { content: “”; display: block; clear: both; }
Slide 39
Box Size Math (container size) 510px / 6 (number of boxes) = 85px (box width)
Slide 40
.box { float: left; background-color: tomato; margin: 20px 0; padding: 20px; color: white; width: 85px; }
Slide 41
Box Size Math (gosh darnit) ((container size) 510px / 6 (number of boxes)) - 40px (padding)
= 45px (box width)
Slide 42
.box { /* … / width: 45px; / or */ width: 85px; box-sizing: border-box; }
Slide 43
This is why we use frameworks
Slide 44
This is why Flex was created
Slide 45
BACK THE TO START <div class=”container”> <div class=”box box1”>1</div> <div class=”box box2”>2</div> <div class=”box box3”>3</div> <div class=”box box4”>4</div> <div class=”box box5”>5</div> <div class=”box box6”>6</div> </div>
Slide 46
.container { display: flex; }
Slide 47
.container { display: flex; } .box { flex: 1; }
Slide 48
Slide 49
<div class=”container”> <div class=”box box1”>1</div> <div class=”box box2”>2</div> <div class=”box box3”>3</div> <!— <div class=”box box4”>4</div> <div class=”box box5”>5</div> <div class=”box box6”>6</div> —> </div>
Slide 50
<div class=”container”> <div class=”box box1”>1</div> <div class=”box box2”>2</div> <div class=”box box3”>3</div> <div class=”box box4”>4</div> <div class=”box box5”>5</div> <div class=”box box6”>6</div> <div class=”box box7”>7</div> </div>
Slide 51
Slide 52
Slide 53
<div class=”container”> <div class=”box two-third”> Box 1 </div> <div class=”box one-third”> Box 2 </div> </div>
Slide 54
.container { display: flex; } .two-third { flex: 2; } .one-third { flex: 1; }
Slide 55
Slide 56
.container { width: 80%; padding: 20px; display: flex; justify-content: space-between; } .two-third { width: 65%; } .one-third { width: 33%; }
Slide 57
Slide 58
.container { justify-content: space-between; // justify-content: space-around; // // justify-content: space-evenly; // // justify-content: center; // justify-content: flex-start; // // justify-content: flex-end; // }
Extra whitespace between elements Extra whitespace split to either side of elements Extra whitespace split evenly around elements and row/column Content center with no whitespace Extra whitespace at the end (default) Extra whitespace at the start
Slide 59
Slide 60
Slide 61
.container { width: 80%; height: 60vh; padding: 20px; display: flex; } .two-third { width: 65%; } .one-third { width: 33%; }
Slide 62
.container { align-items: *default align-items: align-items: align-items: align-items: }
stretch;
// Height stretches to match row
flex-start; flex-end; center; baseline;
// // // // //
Height by content Height by content Height by content Height by content baseline of first
- aligned top - aligned bottom - center aligned - aligned by line of text
Slide 63
Slide 64
Slide 65
.container { flex-direction: row; flex-direction: row-reverse; flex-direction: column; flex-direction: column-reverse;
// // // // // //
Default … it’s a row Reverses the order of the row It’s a column with a simple change in CSS Reverses the direction of the column;
// Column also changes the direction justify and align deal with. }
Slide 66
Slide 67
Slide 68
Learn More • • • •
Flexbox by Animated GIF Flexbox Froggy Flexbox Zombies CSS Tricks Complete Guide to Flexbox
Slide 69
Background Blend Mode CAN THE BROWSER REPLACE PHOTOSHOP?
Slide 70
Support
(FALL FORWARD WITH EYE TOWARD READABILITY)
Slide 71
Slide 72
.box { height: 15vw; margin-bottom: 50px; width: calc(25% - 10px);
}
background-size: cover; background-image: url(https://placekitten.com/1000/800); background-color: purple; background-blend-mode: [value];
Slide 73
normal | multiply | screen | overlay | darken | lighten | color-dodge | color-burn | hard-light | soft-light | difference | exclusion | hue | saturation | color | luminosity
Slide 74
Slide 75
Normal
Multiply
Screen
Overlay
Lighten
Darken
Color Dodge
Hard Light
Difference
Exclusion
Color
Luminosity
Slide 76
Normal
Multiply
Screen
Overlay
Lighten
Darken
Color Dodge
Hard Light
Difference
Exclusion
Color
Luminosity
Slide 77
Normal
Multiply
Screen
Overlay
Lighten
Darken
Color Dodge
Hard Light
Difference
Exclusion
Color
Luminosity
Slide 78
Normal
Multiply
Screen
Overlay
Lighten
Darken
Color Dodge
Hard Light
Difference
Exclusion
Color
Luminosity
Slide 79
background-image: url(https://placekitten.com/1000/800), url(https://placekitten.com/500/500);
Slide 80
Normal
Multiply
Screen
Overlay
Lighten
Darken
Color Dodge
Hard Light
Difference
Exclusion
Color
Luminosity
Slide 81
Normal
Multiply
Screen
Overlay
Lighten
Darken
Color Dodge
Hard Light
Difference
Exclusion
Color
Luminosity
Slide 82
Grid Layout TWO-DIMENSIONAL LAYOUT AT ITS FINEST
Slide 83
Slide 84
Grid Terminology
Grid Line
Grid Cell
Grid Track
Grid Area
SOURCE: COMPLETE GUIDE TO GRID CSS-TRICKS
Slide 85
.container { width: 90%; background-color: lightblue; margin: 30px auto; } .box { background-color: tomato; padding: 10px 20px; margin-bottom: 10px; }
Slide 86
Grid Template Construction .container { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
Slide 87
Grid Template Construction .container { // … grid-template-columns: 100px 1fr 10vw 10%; }
Slide 88
.container { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-gap: 2vw; }
Slide 89
Slide 90
Flex solution: HTML <div class=”promos”> <div class=”left-column”> <a href=”#” class=”promo”>Promo Space 1</a> </div> <div class=”right-column”> <a href=”#” class=”promo”>Promo Space 2</a> <div class=”columns”> <a href=”#” class=”promo”>Promo space 3</a> <a href=”#” class=”promo”>Promo space 4</a> </div> </div> </div>
Slide 91
Flex solution: CSS (a lot) .promos { display: flex; justify-content: space-between; } .promo { display: flex; justify-content: center; align-items: center; min-height: 30vh; } .column { width: calc(50vw - .5rem); display: flex; flex-direction: column; }
.columns { display: flex; justify-content: space-between; } .columns > .promo { flex: 1; } .columns > .promo:first-child { margin-right: 1rem; } .right-column > .promo { margin-bottom: 1rem; } .left-column .promo { height: 100%; }
Slide 92
Slide 93
Grid solution: HTML <div class=”promos”> <a href=”#” class=”promo”>Promo <a href=”#” class=”promo”>Promo <a href=”#” class=”promo”>Promo <a href=”#” class=”promo”>Promo </div>
Space Space space space
1</a> 2</a> 3</a> 4</a>
Slide 94
Grid solution: CSS .promos { display: grid; grid-template-columns: 2fr 1fr 1fr; grid-template-areas: “main second second” “main third fourth”; grid-auto-rows: minmax(20vh, 1fr); grid-gap: 1rem; }
.promo:first-child { grid-area: main; } .promo:nth-child(2) { grid-area: second; } .promo:nth-child(3) { grid-area: third; } .promo:nth-child(4) { grid-area: fourth; }
Slide 95
Learn More • • • • • •
Rachel Andrew’s Grid By Example Layout Land CSSGrid.io PracticalCSSGrid.com CSS Tricks Complete Guide to Grid Jen Simmons’ Lab
Slide 96
CSS Shapes MAKING FLOATING IMAGES INTERESTING AGAIN
Slide 97
Support
(USE BUT DON’T DEPEND ON)
Slide 98
<main class=”container angled”> <div class=”circle”></div> <h1></h1> <p>…</p> <p>…</p> <p>…</p> </main>
Slide 99
shape-outside(circle, polygon, url, content-box)
SHAPE-INSIDE COMING IN LEVEL 2
Slide 100
.circle { float: left; height: 15vw; width: 15vw; background-color:limegreen; border-radius: 50%; shape-outside: circle(); }
Slide 101
<main class=”container angled”> <div class=”polygon”></div> <h1></h1> <p>…</p> <p>…</p> <p>…</p> </main>
Slide 102
.polygon { float: left; width: 200px; height: 400px; shape-outside: polygon(22% 0, 23% 18%, 79% 25%, 90% 36%, 66% 56%, 75% 80%, 28% 101%, 45% 60%, 45% 40%); }
POLYGON CREATOR: HTTP://BENNETTFEELY.COM/CLIPPY/
Slide 103
<main class=”container angled”> <img src=“Image.png” alt=”” /> <h1></h1> <p>…</p> <p>…</p> <p>…</p> </main>
Slide 104
img { float: left; shape-outside: url(mask.png); shape-margin: 10px; }
Slide 105
<main class=”container angled”> <aside class=”left”></aside> <aside class=”right”></aside> <h1></h1> <p>…</p> <p>…</p> <p>…</p> </main>
Slide 106
.left { float: left; width: 20%; height: 730px; shape-outside: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); } .right { float: right; width: 20%; height: 730px; shape-outside: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
Slide 107
Slide 108
Explore More •
Initial Letter
•
CSS Transforms
•
Object-Fit
•
CSS Filters
•
Clip Path
Slide 109
No Shame in Templates BUT UNDERSTAND WHAT THE TEMPLATE DOES AND HOW TO BREAK OUT
Slide 110
CSS is Powerful LEARN A FEW THINGS AND MAKE INTERESTING DESIGNS
Slide 111
Start Today YOU DON’T HAVE TO WAIT FOR 100% BROWSER ADOPTION
Slide 112
WAIT A SECOND!
No More “Fallbacks”
WRITE SUPPORT-FIRST CSS AND FALL FORWARD INTO THE NEW
Slide 113
Support our Asymmetry .promos { display: flex; justify-content: space-between; } .promo { width: calc(50% - .5rem); margin-bottom: 1rem; } @supports (display: grid) { .promo { width: 100%; margin-bottom: 0; } /* The rest of our grid code */ }
Slide 114
Homework LEARN ONE NEW LAYOUT AND ONE NEW STYLE PROPERTY THEN TWEET AT ME (@BROB) TO LET ME KNOW WHAT YOU PICKED
Slide 115
I’d love to help you •
http://bryanlrobinson.com
•
Twitter: @brob
•
Twitch: https://twitch.tv/ bryanlrobinson