Slide 1
DESIGNING
LAYOUTS:
THE NEW
SUPERPOWERS OF CSS
WITH JEN SIMMONS
Slide 2
Slide 3
Slide 4
The Cheongju Early Printing Museum, Korea —
lindagoeseast.com/2015/09/14/a-visit-to-the-cheongju-early-printing-museum
Slide 5
Slide 6
Slide 7
Slide 8
Slide 9
Slide 10
Slide 11
Slide 12
Slide 13
Slide 14
Slide 15
Slide 16
Slide 17
Slide 18
Slide 19
Slide 20
Slide 21
Slide 22
Slide 23
Slide 24
Slide 25
Slide 26
Slide 27
Slide 28
Slide 29
Slide 30
Slide 31
Slide 32
Slide 33
Slide 34
Slide 35
Slide 36
Slide 37
Slide 38
Slide 39
Slide 40
Slide 41
Slide 42
Slide 43
Slide 44
Slide 45
Slide 46
Slide 47
Slide 48
Slide 49
Slide 50
Hot metal composition: Pasteup ::
Floats : CSS Grid
Slide 51
Slide 52
9:00 – now
Intro
now – 10:00
Writing Modes
10:00 – 10:10
Break
10:10 – 11:00
Alignment, Logical Properties & bit for Flexbox
11:00 – 11:10
Break
11:10 - 12:00
Intro to CSS Grid
12:00 – 1:00
Lunch
1:00 – 2:00
CSS Grid
2:00 - 2:10
Break
2:10 – 3:00
More CSS Grid
3:00 – 3:10
Break
3:10 - 4:00
More bits
Slide 53
labs.jensimmons.com/2017/aeabos
Slide 54
Slide 55
Slide 56
Slide 57
“
— Bruce Lawson
It
’s
the World Wide Web, not
the Wealthy Western Web.
Slide 58
Slide 59
drafts.csswg.org/css-writing-modes
Slide 60
direction
writing-mode
text-orientation
Slide 61
inline direction
When I’m writing or reading this is the way the characters flow
Slide 62
<p
>
<p
>
<p
>
<p
>
block
flow
direction
Slide 63
div {
display: block;
}
<div
>
<div
>
<div
>
<div
>
Slide 64
div {
display: inline;
}
<div
>
<div
>
<div
>
<div
>
Slide 65
div {
display: inline-block;
}
<div
>
<div
>
<div
>
<div
>
Slide 66
display: block;
display: inline;
display: inline-block;
Slide 67
developer.mozilla.org/docs/Web/CSS/display
Slide 68
display: block;
div
h1
p
figure
figcaption
header
main
aside
display: inline;
span
i
em
a
img
Default CSS on HTML elements
Slide 69
Slide 70
Slide 71
Slide 72
block
direction
inline direction
A
character orientation
Slide 73
LATIN-LIKE SYSTEMS
block
direction
inline direction
A
character
orientation
Slide 74
Slide 75
ARABIC-LIKE
SYSTEMS
inline direction
block
direction
A
character
orientation
Slide 76
Slide 77
.foo { direction: ltr; }
.foo { direction: rtl; }
Slide 78
Slide 79
<!DOCTYPE html>
<html lang="en-US" dir="ltr"
>
<head> … </head>
<body> … </body>
</html>
Slide 80
<
p>English words</p>
<p><bdo dir="
rtl">
.
ﺔﯿﺑﺮﻌﻟا
تﺎﻤﻠﻜﻟا
</bdo></p>
Slide 81
<p>English words in this paragraph.
<bdi dir="rtl">.
تﺎﻤﻠﻜﻟ
</bdi> Some
more LTR words, same paragraph.</p>
Slide 82
LATIN-LIKE
SYSTEMS
ARABIC-LIKE
SYSTEMS
block
direction
inline direction
block
direction
inline direction
.css {direction: ltr;}
<html dir="ltr"
>
<bdo dir="ltr"
>
<bdi dir="ltr"
>
.css {direction: rtl;}
<html dir="rtl"
>
<bdo dir="rtl"
>
<bdi dir="rtl"
>
Slide 83
Slide 84
MONGOLIAN-LIKE
SYSTEMS
block
direction
inline direction
Slide 85
MONGOLIAN-LIKE
SYSTEMS
block
direction
inline direction
Slide 86
HAN-LIKE
SYSTEMS
block
direction
inline direction
*Chinese, Japanese, Korean & more
Slide 87
HAN-LIKE
SYSTEMS
block
direction
inline direction
block
direction
inline direction
*Chinese, Japanese, Korean & more
Slide 88
Slide 89
Slide 90
Slide 91
Slide 92
HAN-BASED SYSTEMS
block
direction
inline direction
block
direction
inline direction
*Chinese, Japanese, Korean & more
Slide 93
Slide 94
THREE OPTIONS FOR WRITING-MODE
writing-mode:
vertical-lr;
writing-mode:
vertical-rl;
toggle w/
dir
writing-mode:
horizontal-tb;
Slide 95
Slide 96
Slide 97
chenhuijing.com/blog/chinese-web-typography
Slide 98
Slide 99
Slide 100
Slide 101
h1:nth-child(2) {
writing-mode: vertical-rl;
}
Slide 102
NOPE!
- text flowing
- like this
writing-mode: vertical-lr;
- text flowing
- like this
writing-mode: vertical-rl;
Slide 103
Slide 104
Slide 105
Top of
page
Top of
(Latin-like)
characters
hello
A
Slide 106
- like this
- text flowing
- text flowing
- like this
MONGOLIAN
-LIKE SYSTEMS
HAN-LIKE SYSTEMS
Slide 107
THREE OPTIONS FOR WRITING-MODE
direction
block
inline direction
writing-mode:
vertical-lr;
block
direction
inline direction
writing-mode:
vertical-rl;
block
direction
inline direction
toggle w/
dir
writing-mode:
horizontal-tb;
creates a
vertical
typographic mode
Slide 108
TWO MORE (FUTURE) OPTIONS FOR WRITING-MODE
block
direction
inline direction
writing-mode:
sideways-lr;
block
direction
inline direction
writing-mode:
sideways-rl;
creates a
horizontal
typographic mode
only
A
A
Slide 109
block
direction
inline direction
writing-mode:
sideways-rl;
block
direction
inline direction
writing-mode:
vertical-rl;
A
È
Slide 110
direction
block
inline direction
writing-mode:
vertical-lr;
block
direction
inline direction
writing-mode:
sideways-lr;
A
Slide 111
creates a
vertical
typographic mode
THREE OPTIONS FOR WRITING-MODE
direction
block
inline direction
writing-mode:
vertical-lr;
block
direction
inline direction
writing-mode:
vertical-rl;
block
direction
inline direction
toggle w/
dir
writing-mode:
horizontal-tb;
Slide 112
Slide 113
Slide 114
Slide 115
My Cool Website
writing-mode: vertical-rl;
transform: rotate(180deg)
;
text-orientation: sideways;
(needed to fix punctuation / underlining)
text-align: right;
Slide 116
Slide 117
Slide 118
Slide 119
options for vertical
writing modes
text-orientation:
mixed;
text-orientation:
upright;
text-orientation:
sideways;
THREE OPTIONS FOR TEXT-ORIENTATION
Slide 120
Slide 121
Slide 122
block
direction
inline direction
writing-mode:
sideways-rl;
block
direction
inline direction
writing-mode:
vertical-rl;
text-orientation: mixed;
creates a
horizontal
typographic mode
creates a
vertical
typographic mode
Slide 123
My Cool Website
writing-mode: vertical-rl;
transform: rotate(180deg)
;
text-orientation: sideways;
(needed to fix punctuation / underlining)
text-align: right;
Slide 124
Slide 125
block
direction
inline direction
A
character orientation
Slide 126
Slide 127
Slide 128
HAN-LIKE
SYSTEMS
*Chinese, Japanese, Korean & more
È
È
Slide 129
Slide 130
dir
writing-mode
text-orientation
Slide 131
LATIN-LIKE
SYSTEMS
ARABIC-LIKE
SYSTEMS
block
direction
inline direction
block
direction
inline direction
.css {direction: ltr;}
<html dir="ltr"
>
<bdo dir="ltr"
>
<bdi dir="ltr"
>
.css {direction: rtl;}
<html dir="rtl"
>
<bdo dir="rtl"
>
<bdi dir="rtl"
>
A
A
Slide 132
THREE OPTIONS FOR WRITING-MODE
direction
block
inline direction
writing-mode:
vertical-lr;
block
direction
inline direction
writing-mode:
vertical-rl;
block
direction
inline direction
toggle w/
direction
writing-mode:
horizontal-tb;
creates a
vertical
typographic mode
È
È
A
Slide 133
TWO MORE (FUTURE) OPTIONS FOR WRITING-MODE
block
direction
inline direction
writing-mode:
sideways-lr;
block
direction
inline direction
writing-mode:
sideways-rl;
creates a
horizontal
typographic mode
only
A
A
Slide 134
options for vertical
writing modes
text-orientation:
mixed;
text-orientation:
upright;
text-orientation:
sideways;
THREE OPTIONS FOR TEXT-ORIENTATION
Slide 135
Slide 136
section {
direction: ltr;
writing-mode: horizontal-tb;
}
(These are all the defaults.
No need to specify them.)
Example:
Writing Mode 1A
Slide 137
<section><bdo dir="rtl"
>
...
</bdo></section>
Example:
Writing Mode 1A
Slide 138
section {
writing-mode: vertical-rl;
}
(This triggers
text-orientation: mixed
as the default.)
Example:
Writing Mode 1A
Slide 139
section {
writing-mode: vertical-lr;
}
Example:
Writing Mode 1A
Slide 140
section {
writing-mode: sideways-rl;
}
Example:
Writing Mode 1A
Slide 141
section {
writing-mode: sideways-lr;
}
Example:
Writing Mode 1A
Slide 142
section {
writing-mode: vertical-rl;
text-orientation: upright;
}
Example:
Writing Mode 1A
Slide 143
section {
writing-mode: vertical-lr;
text-orientation: upright;
}
Example:
Writing Mode 1A
Slide 144
QUESTION TIME
COMING SOON
Slide 145
h1 {
writing-mode: vertical-rl;
}
Example: Writing Mode
4A
Slide 146
h1 {
writing-mode: vertical-rl;
transform: rotate(180deg);
text-align: right;
}
Example: Writing Mode
4B
Slide 147
h1 {
writing-mode: vertical-rl;
text-orientation: upright;
text-transform: uppercase;
}
Example: Writing Mode
4C
Slide 148
h1 {
writing-mode: vertical-rl;
text-orientation: upright;
text-transform: uppercase;
transform: rotate(180deg);
}
Example: Writing Mode
4D
Slide 149
Slide 150
Slide 151
<main>
<h1>
<span>Made</span>
<span>by</span>
<span>Few</span>
</h1>
</main>
Example: Writing Mode 3
A
Slide 152
h1 span:nth-child(2) {
writing-mode: vertical-rl;
text-orientation: upright;
font-size: 45%;
}
Example: Writing Mode 3
A
Slide 153
h1 {
display: grid;
}
h1 span:nth-child(1) {
grid-column: 1 / 3;
grid-row: 1 / 2;
}
h1 span:nth-child(2) {
grid-column: 1 / 2;
grid-row: 2 / 3;
}
h1 span:nth-child(3) {
grid-column: 2 / 3;
grid-row: 2 / 3;
}
Example: Writing Mode 3
A
Slide 154
Slide 155
Slide 156
Slide 157
block
direction
inline direction
A
character orientation
Slide 158
Slide 159
Slide 160
block end
inline
start
inline
end
block start
Slide 161
block end
inline start
inline end
block start
Slide 162
block start
inline start
inline end
block end
Slide 163
block start
inline end
inline start
block end
Slide 164
Slide 165
Slide 166
Slide 167
margin-block-start: 1rem;
padding-inline-end: 1rem;
border-block-end: 1px solid black;
text-align: start;
float: inline-start;
Slide 168
Slide 169
drafts.csswg.org/css-logical
Slide 170
Slide 171
Slide 172
flex-start
flex-end
center
stretch
space-between
space-around
Slide 173
start / flex-start
end / flex-end
center
space-between
space-around
space-evenly
stretch
Slide 174
flex-start
flex-end
center
stretch
baseline
Slide 175
Slide 176
(put on the container)
*-content
effects content group
*-items
effects individual items
(put on item)
*-self
effects
individual items
Slide 177
Slide 178
Slide 179
Slide 180
Slide 181
Slide 182
Slide 183
start
center
end
s t r e t c
h
Justify
Slide 184
start
center
end
s
t
r
e
t
c
h
Align
Slide 185
cross axis
main axis
flex-direction: row;
Slide 186
cross axis
main axis
Justify
Align
flex-direction: row;
Slide 187
main axis
Justify
cross axis
Align
flex-direction: column;
Slide 188
Grid
Justify
1
4
5
2
3
6
8
7
9
Align
writing-mode: horizontal-tb;
grid-auto-flow: row;
Slide 189
Grid
Justify
1
4
5
2
3
6
8
7
9
writing-mode: horizontal-tb;
grid-auto-flow: column;
Align
Slide 190
Slide 191
Slide 192
Slide 193
Slide 194
flexboxdefense.com flexboxfroggy.com
Slide 195
Slide 196
FAQ:
F
le
x
box vs.
CSS
Grid?
Slide 197
F lex box line s t hings up
in one direction
Slide 198
Gr id line s t hings up
in two directions
Slide 199
Slide 200
Slide 201
Slide 202
Slide 203
Slide 204
Slide 205
Slide 206
Slide 207
Bot h super powers are u se ful .
Which do you want?
Slide 208
Slide 209
Slide 210
Slide 211
Slide 212
Slide 213
Slide 214
Yo u m u s t s u p p o r t
browsers that
do not understand
CSS Grid.
Slide 215
Slide 216
Slide 217
Works
Doesn’t
work
Use It
Don’t
Use It
Slide 218
Works
Doesn’t
work
Use It
Don’t
Use It
Slide 219
Works
Doesn’t
work
Use It
Don’t
Use It
Slide 220
Works
Doesn’t
work
Use It
Don’t
Use It
Fired.
Slide 221
Works
Doesn’t
work
Use It
Don’t
Use It
Fired.
Slide 222
Works
Doesn’t
work
Use It
Don’t
Use It
Fired.
✔
Slide 223
Works
Doesn’t
work
Use It
Don’t
Use It
Slide 224
Works and
Doesn’t Work
Use It and
Don’t Use It
Don’t
Use It
Slide 225
X
Works and
Doesn’t Work
Use It and
Don’t Use It
Don’t
Use It
Slide 226
.box {
background: #bbb;
border: 10px solid black;
border-radius: 50px;
}
Slide 227
Slide 228
.box {
background: #bbb;
border: 10px solid black;
border-radius: 50px;
}
Slide 229
.box {
background: #bbb;
border: 10px solid black;
border-radius: 50px;
}
.box {
background: #bbb;
border: 10px solid black;
border-radius: 50px;
}
Opera Mini
IE8
IE7
IE6
Firefox
Safari
Chrome
IE9+
Edge
(on all operating systems)
Slide 230
Slide 231
Slide 232
img {
width: 200px;
margin: 0 1.5em 0.5em 0;
float: left;
shape-outside: circle()
;
}
There is a prefix:
-webkit-shape-outside: circle();
*
Slide 233
img {
width: 200px;
margin: 0 1.5em 0.5em 0;
float: left;
shape-outside: circle()
;
}
There is a prefix:
-webkit-shape-outside: circle();
*
Slide 234
Slide 235
Slide 236
Slide 237
p::first-letter {
color: rgba(255,190,150,0.9);
font-weight: bold;
margin-right: 0.5em;
-webkit-initial-letter: 4;
initial-letter: 4;
}
Slide 238
p::first-letter {
color: rgba(255,190,150,0.9);
font-weight: bold;
margin-right: 0.5em;
-webkit-initial-letter: 4;
initial-letter: 4;
}
Slide 239
@supports (initial-letter: 4 ) or
(-webkit-initial-letter: 4 )
{
p::first-letter {
color: rgba(255,190,150,0.9);
font-weight: bold;
margin-right: 0.5em;
-webkit-initial-letter: 4;
initial-letter: 4;
}
}
Slide 240
@supports (foo: value)
{
// some code here
}
Slide 241
hacks.mozilla.org/2016/08/using-feature-queries-in-css
Slide 242
jensimmons.com/
presentation/
progressing-our-
layouts
Slide 243
//
simplified layout
//
for older browsers
@supports (display: grid) {
// code for newer browsers
// including overrides
}
Slide 244
Slide 245
Slide 246
Slide 247
Slide 248
Slide 249
//
simplified layout
//
for older browsers
@supports (display: grid) {
// code for newer browsers
// including overrides
}
Slide 250
Slide 251
Slide 252
Slide 253
Slide 254
Slide 255
Yo u h a v e t w o c h o i c e s fo r
Internet Explorer (& Edge):
- Leverage the 2012 Grid
implementation.
- Pretend IE has no Grid.
Slide 256
Yo u h a v e t w o c h o i c e s fo r
Internet Explorer (& Edge):
- Use old -ms-* syntax.
- Or don’t.
Slide 257
display: grid;
grid-template-columns: repeat(4, 100px)
;
display: -ms-grid;
-ms-grid-columns: (100px)[4]
;
Slide 258
Slide 259
rachelandrew.co.uk/archives/2016/11/26/should-i-tr y-
to-use-the-ie-implementation-of-css-grid-layout
Slide 260
Slide 261
// for non-Grid browsers
@supports (display: grid)
or
(display: -ms-grid)
{
// for
IE, Edge
// and for modern-Grid-supporting
}
Slide 262
// for non-Grid browsers
@supports (display: grid) {
// for modern-Grid-supporting
}
@supports (display: -ms-grid) {
// for IE, Edge
}
Slide 263
Slide 264
Slide 265
Slide 266
Slide 267
Slide 268
Slide 269
Slide 270
<main>
<div>item</div>
<div>item
</div>
<div>item
</div>
this is an anonymous grid item
<div>item
</div>
hello world
<section>more stuff</section
>
<footer>conclusion</footer>
</main>
<ul>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
</ul>
<body>
<header>
<main>
<article>
<h1>
<p>
<figure>
<aside>
<footer>
</body>
Slide 271
<body>
<header>…</header>
<main>
<article>
<h1>
<p>
<p>
<p>
<figure>
<p>
</article>
</main>
<aside>…</aside>
<footer>…</footer>
</body>
body {
display: grid;
}
Slide 272
<body>
<header>…</header>
<main>
<article>
<h1>
<p>
<p>
<p>
<figure>
<p>
</article>
</main>
<aside>…</aside>
<footer>…</footer>
</body>
body {
display: grid;
}
article {
display: grid;
}
Slide 273
<body>
<header>…</header>
<main>
<article>
<h1>
<p>
<p>
<p>
<figure>
<p>
</article>
</main>
<aside>…</aside>
<footer>…</footer>
</body>
body {
display: grid;
}
main {
display: subgrid;
}
article {
display: subgrid;
}
Slide 274
<body>
<header>…</header>
<main>
<article>
<h1>
<p>
<p>
<p>
<figure>
<p>
</article>
</main>
<aside>…</aside>
<footer>…</footer>
</body>
body {
display: grid;
}
article {
display: grid;
}
Slide 275
<ul>
<li>…</li>
<li>
<h1>…</h1>
<img>
<p>…</p>
</li>
<li>…</li>
<li>…</li>
<li>…</li>
<li>…</li>
<li>…</li>
<li>…</li>
<li>…</li>
</ul>
ul {
display: grid;
grid-template-columns:
repeat(auto-fit,
minmax(100px, 1fr));
grid-gap: 0.5rem 1rem;
}
li {
// are Grid items
display: flex;
flex-flow: column;
}
img {
order: -1;
}
Slide 276
Headline Here
This is teaser text. It
comes in different lengths.
Headline Here
This is teaser text. It
comes in different lengths.
Here we see more content
filling the box up all the way.
Headline
This is teaser text.
Headline That is
Longer & Wraps
This is teaser text. It
comes in different lengths.
Headline
This Headline
This is teaser text. It
comes in different lengths.
Slide 277
Headline Here
This is teaser text. It
comes in different lengths.
Headline Here
This is teaser text. It
comes in different lengths.
Here we see more content
filling the box up all the way.
Headline
This is teaser text.
Headline That is
Longer & Wraps
This is teaser text. It
comes in different lengths.
Headline
This Headline
This is teaser text. It
comes in different lengths.
Slide 278
Headline Here
This is teaser text. It
comes in different lengths.
Headline Here
This is teaser text. It
comes in different lengths.
Here we see more content
filling the box up all the way.
Headline
This is teaser text.
Headline That is
Longer & Wraps
This is teaser text. It
comes in different lengths.
Headline
This Headline
This is teaser text. It
comes in different lengths.
Slide 279
Headline Here
This is teaser text. It
comes in different lengths.
Headline Here
This is teaser text. It
comes in different lengths.
Here we see more content
filling the box up all the way.
Headline
This is teaser text.
Headline That is
Longer & Wraps
This is teaser text. It
comes in different lengths.
Headline
This Headline
This is teaser text. It
comes in different lengths.
Slide 280
Headline Here
This is teaser text. It
comes in different lengths.
Headline Here
This is teaser text. It
comes in different lengths.
Here we see more content
filling the box up all the way.
Headline
This is teaser text.
Headline That is
Longer & Wraps
This is teaser text. It
comes in different lengths.
Headline
This Headline
This is teaser text. It
comes in different lengths.
Slide 281
Slide 282
Slide 283
Slide 284
Slide 285
Slide 286
Slide 287
Grid Area
Grid Line
Grid Track
Grid Track
Grid Cell
Grid Line
Grid Line
Grid Line
Grid Line
Slide 288
Grid Area
Grid Track
Grid Track
Grid
Cell
Grid Line
Grid Line
Grid Line
Grid Line
Grid Line
Grid Gap
Grid Gap
Grid Gap
Slide 289
Slide 290
•
Exists in HTML
•
Can be styled,
like anything in HTML
Slide 291
•
Exists in CSS
•
Can NOT be styled
•
It doesn’t exist
in the DOM
Slide 292
Slide 293
labs.jensimmons.com/2017/01-003.html
Slide 294
Slide 295
Slide 296
Slide 297
Slide 298
Slide 299
ul {
display: grid;
grid-template-columns:
repeat(4, 100px);
grid-gap: 4px;
}
li {
// nothing
}
Slide 300
Slide 301
Slide 302
<ul>
<li><img src="/file1.jpg"
></li>
<li><img src="/file2.jpg"
></li>
<li><img src="/file3.jpg"
></li>
<li><img src="/file4.jpg"
></li>
<li><img src="/file5.jpg"
></li>
<li><img src="/file6.jpg"
></li>
<li><img src="/file7.jpg"
></li>
</ul>
Slide 303
ul {
display: grid;
grid-template-columns:
repeat(4, 100px);
grid-gap: 4px;
}
li {
// nothing
}
img { display: block; width: 100%; }
Slide 304
Slide 305
ul {
display: grid;
grid-template-columns:
repeat(4, 100px);
grid-gap: 4px;
}
/*
or */
ul {
display: grid;
grid-template-columns: 100px 100px 100px
100px;
grid-gap: 4px;
}
Slide 306
Slide 307
Slide 308
ul {
display: grid;
grid-template-columns: repeat(5, 1fr
);
grid-gap: 0.25em;
}
/*
or */
ul {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr
;
grid-gap: 0.25em;
}
Slide 309
Slide 310
10 0 %
31. 6 6 6
%
31. 6 6 6
%
31. 6 6
6%
2.5%
2.5%
100% – 5% = 95% = 31.666666666666666%
3
3
Slide 311
10 0 %
1fr
1fr
1fr
2em
2em
Slide 312
1fr
1fr
1fr
1fr + 1fr + 1fr = 3fr total
therefore, 1fr = 1/3 of the space
Slide 313
1fr
1fr
1fr
1fr + 1fr + 1fr + 1fr = 4fr total
therefore, now 1fr = 1/4 of the space
1fr
Slide 314
2fr + 1.5fr + 1fr = 4.5fr total
therefore, now 1fr = 2/9ths of the space
2fr
1fr
- 5 f r
Slide 315
2fr
1fr
50px
1fr
min-content
Slide 316
ul {
display: grid;
grid-template-columns: repeat(5, 1fr
);
grid-gap: 0.25em;
}
/*
or */
ul {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr
;
grid-gap: 0.25em;
}
Slide 317
Slide 318
grid-template-columns: repeat(5, 1fr
);
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
Slide 319
Slide 320
ul {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
grid-gap: 0.25rem;
}
Slide 321
ul {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
grid-gap: 0.25rem;
}
/*
or */
ul {
display: grid;
grid-template-columns: repeat(auto-fill
, minmax(120px, 1fr));
grid-gap: 0.25rem;
}
Slide 322
Slide 323
gridbyexample.com/video/series-auto-fill-auto-fit
Slide 324
Slide 325
Options for
grid-template-columns
grid-template-rows
Slide 326
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
some other syntax options (each with different results)
grid-template-columns: 1fr 5fr 2.5fr;
grid-template-columns: 8em 1fr 300px;
grid-template-columns: 1fr 1fr 2fr 3fr 5fr 8fr 13fr 21fr 34fr
;
grid-template-columns: repeat(7, 1fr);
grid-template-columns: repeat(3, 200px 1fr 25%);
grid-template-columns: repeat(auto-fill, 10rem);
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-template-columns: 4rem 2fr repeat(5, 1fr) 300px;
Slide 327
Units for setting Grid Track Sizes
‣
length: px, em, rem, vw, vh
‣
percent
‣
fraction unit: 1fr
‣
minmax();
‣
size of content:
min-content / max-content / fit-content
‣
auto
Slide 328
ul {
display: grid;
grid-template-columns:
repeat(auto-fit,
minmax(120px, 1fr));
grid-gap: 0.25rem;
// nothing about rows
}
li {
// nothing needed
}
Slide 329
Slide 330
You define
!
e size and/or
number of rows
and/or
columns
Let
!
e browser
define number or
size of rows
or columns
Slide 331
P lace each
"
em
into a specific
cell or area
Let
!
e browser
place every
!
ing
using
auto-placement
a
lgor
"
hm
Slide 332
Slide 333
Slide 334
ul {
display: grid;
grid-template-columns:
repeat(4, 1fr);
}
Slide 335
li:nth-child(1) {
grid-column: 2 / 3;
grid-row: 1 / 2;
}
Slide 336
li:nth-child(1) {
grid-column: 2 / 3;
grid-row: 1 / 2;
}
li:nth-child(2) {
grid-column: 4 / 5;
grid-row: 2 / 3;
}
li:nth-child(3) {
grid-column: 3 / 4;
grid-row: 3 / 4;
}
li:nth-child(4) {…}
li:nth-child(5) {
…}
Slide 337
.item {
grid-row-start: 1;
grid-row-end: 3;
grid-column-start: 2;
grid-column-end: 4;
}
.item {
grid-row: 1 / 3;
grid-column: 2 / 4;
}
.item {
grid-area: 1 / 2 / 3 / 4;
}
1
2
3
4
grid-column: 2 / 4;
grid-row: 1 / 3;
1
2
3
4
5
Slide 338
Slide 339
Slide 340
Slide 341
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-columns: 2fr 4fr 3fr 1fr;
grid-template-columns: repeat(auto-fill, minmax(200px,1fr));
grid-gap: 1rem;
grid-auto-flow: dense;
li:nth-child(2) { }
grid-row: 1 / 2;
grid-column: 1 / 2;
grid-row: span 2;
grid-column: span 2;
Some bits for the Exercises
Slide 342
Slide 343
1
2
3
4
5
6
Grid Line Numbers
Line
Numbers,
not track numbers —
different than what
we are used to!
1
2
3
4
5
Slide 344
1
6
6 lines
5 tracks
4 gaps
2
3
4
5
Slide 345
1
2
3
4
5
6
grid-row: 1 / 2;
grid-column: 1 / 2;
grid-row: 1 / 2;
grid-column: 5 / 6;
grid-row: 2 / 3;
grid-column: 2 / 4;
grid-row: 3 / 5;
grid-column: 3 / 5;
1
2
3
4
5
grid-row: 4 / 5;
grid-column: 1 / 2;
Slide 346
.item-A {
grid-row: 1 / 3;
grid-column: 2 / 4;
}
.item-B {
grid-row: 4 / 5;
grid-column: 1 / 2;
}
.item-C {
grid-row: 4;
grid-column: 3;
}
1
2
3
4
grid-row: 1 / 3;
grid-column: 2 / 4;
1
2
3
4
5
grid-row: 4 / 5;
grid-column: 1 / 2;
grid-row: 4;
grid-column: 3;
Slide 347
.item {
grid-area: 1 / 2 / 3 / 4;
}
.item {
grid-row-start: 1;
grid-column-start: 2;
grid-row-end: 3;
grid-column-end: 4;
}
1
2
3
4
1
2
3
4
5
Slide 348
.item {
grid-area: 1 / 2 / 3 / 4;
}
1
2
3
4
1
2
3
4
5
first
second
third
fourth
Slide 349
Slide 350
.item {
grid-area: 1 / 2 / 3 / 4;
}
.item-B {
grid-area: 4 / 1;
}
1
2
3
4
1
2
3
4
5
first
second
third
fourth
Slide 351
ul {
display: grid;
grid-template-columns:
4fr 2fr 2fr 3fr 6fr
;
}
Slide 352
Slide 353
li:nth-child(1) {
grid-row: 1 / 3
;
grid-column: 1 / 3;
z-index: 2;
}
li:nth-child(2
) {
grid-row: 2 / 6
;
grid-column: 2 / 5;
}
li:nth-child(3
) {
grid-row: 4 / 7
;
grid-column: 4 / 6;
z-index: 2;
}
Slide 354
li:nth-child(1) {
grid-row: 1 / span 2
;
grid-column: 1 / span 2;
z-index: 2;
}
li:nth-child(2
) {
grid-row: 2 / span 4
;
grid-column: 2 / span 3;
}
li:nth-child(3
) {
grid-row: 4 / span 3
;
grid-column: 4 / span 2;
z-index: 2;
}
Slide 355
These all have the same results:
grid-column: 1 / 4; // starts at line 1, goes to line 4
grid-column: 1 / span 3; // starts at line 1, spans 4 cells
grid-column: span 3 / 4; // spans 3 cells, ends at line 4
1
2
3
4
5
1
2
Slide 356
.grid-item {
grid-column: 1 / 5; // goes from vertical line 1 to 5
grid-row: 3 / 5 // goes from horizontal line 3 to 5
}
some other syntax options (with some different results)
grid-column: 3 / 5; // starts at line 3, goes to line 5
grid-column: 3 / span 2; // starts at line 3, spans 2 cells
grid-column: span 2 / 5; // spans 2 cells, ends at line 5
grid-column: span 2; // spans 2 cells, placed by algorithm
grid-column: 4; // starts at line
4, spans 1 cell
grid-column: 1 / -1; // starts at line 1, goes to line -1
grid-column: horse / pig;
Slide 357
Slide 358
Slide 359
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-columns: 2fr 4fr 3fr 1fr;
grid-template-columns: repeat(auto-fill, minmax(200px,1fr));
grid-gap: 1rem;
grid-auto-flow: dense;
li:nth-child(2) { }
grid-row: 1 / 2;
grid-column: 1 / 2;
grid-row: span 2;
grid-column: span 2;
Some bits for the Exercises
Slide 360
Slide 361
Grid Line Numbers
1
2
3
4
5
6
-5
-4
-3
-2
-1
-6
-5
-4
-3
-2
-1
1
2
3
4
5
Slide 362
main {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-template-rows: repeat(4, 1fr);
}
aside {
grid-column: 1 / 3;
grid-row: 1 / -1;
background: yellow;
}
Slide 363
Slide 364
15
16
17
12
4
3
13
11
8
9
10
6
5
1
2
auto placement
algorithm
7
14
.container {grid-auto-flow: row;}
Slide 365
15
10
6
2
14
7
16
17
12
4
3
13
11
8
9
5
1
grid-auto-flow: column;
Slide 366
Grid
Justify
1
4
5
2
3
6
8
7
9
writing-mode: horizontal-tb;
grid-auto-flow: column;
Align
Slide 367
Row
Column
writing-mode: horizontal-tb;
Slide 368
Column
Row
writing-mode: vertical-*;
Slide 369
15
10
6
2
14
7
16
17
12
4
3
13
11
8
9
5
1
grid-auto-flow: column;
writing-mode: horizontal-tb;
Slide 370
15
16
17
12
4
3
13
11
8
9
10
6
5
1
2
7
14
grid-auto-flow: row;
writing-mode: horizontal-tb;
Slide 371
13
11
8
9
10
7
6
5
1
2
3
4
12
grid-auto-flow: row;
grid-column: span 2;
grid-row: span 2;
grid-column: span 2;
grid-row: span 2;
grid-column: span 2;
Slide 372
13
11
8
9
10
7
6
5
1
2
3
4
12
grid-auto-flow: dense;
Slide 373
grid-auto-flow: row;
grid-auto-flow: column;
grid-auto-flow: dense;
grid-auto-flow: row dense;
grid-auto-flow: column dense;
Slide 374
Slide 375
Slide 376
Slide 377
Slide 378
Slide 379
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-columns: 2fr 4fr 3fr 1fr;
grid-template-columns: repeat(auto-fill, minmax(200px,1fr));
grid-gap: 1rem;
grid-auto-flow: dense;
li:nth-child(2) { }
grid-row: 1 / 2;
grid-column: 1 / 2;
grid-row: span 2;
grid-column: span 2;
Some bits for the Exercises
Slide 380
Slide 381
.container {
grid-template-rows: 1fr 1fr 1fr;
}
Slide 382
.container {
grid-template-rows:[cow] 1fr [horse] 1fr [dog] 1fr [pig];
}
Slide 383
1
2
3
4
1
2
3
4
5
cow
horse
dog
pig
.container {
grid-template-rows:[cow] 1fr
[horse]
1fr [dog] 1fr [pig];
}
.item {
grid-row: 3;
grid-column: horse / pig;
}
Slide 384
grid-template-rows:
1fr 1fr 1fr;
grid-template-rows:[cow] 1fr [horse] 1fr [dog] 1fr [pig];
grid-template-rows:[cow truck] 1fr [horse car] 1fr [dog boat];
grid-template-rows: repeat(auto-fit, 200px 1fr);
grid-template-rows: repeat(auto-fit, [dog] 200px [cat] 1fr);
grid-template-rows: repeat(4,
[
even-start even-end] 80px [odd-start odd-end] 80px);
Slide 385
.container {
grid-template-rows:[main-start] 1fr [main-end];
}
Slide 386
Slide 387
Grid Area
Grid Line
Grid Track
Grid Track
Grid Cell
Grid Line
Grid Line
Grid Line
Grid Line
Slide 388
<body>
<header>…</header>
<main>…</main>
<aside>…</aside>
<footer>…</footer>
</body>
~25%
~75%
Slide 389
header
{
grid-area: header;
}
main
{
grid-area: content;
}
aside
{
grid-area: sidebar;
}
footer
{
grid-area: footer;
}
‘header’
‘sidebar’
‘content’
‘footer’
Slide 390
header { grid-area: header;
}
main { grid-area: main;
}
aside { grid-area: aside;
}
footer { grid-area: footer; }
body {
display: grid;
grid-template-columns: 3fr 1fr;
grid-gap: 2rem;
grid-template-areas:
"header
header"
"content sidebar
"
"footer footer"
;
}
‘header’
‘aside’
1fr
‘main’
3fr
‘footer’
Slide 391
body {
display: grid;
grid-gap: 2rem;
grid-template-areas:
"header"
"content"
"sidebar
"
"footer"
;
}
@media (min-width: 800px) {
body {
grid-template-columns:
3fr 1fr;
grid-template-areas:
"header header"
"content sidebar
"
"footer footer"
;
}
}
Slide 392
Slide 393
Slide 394
@media (min-width: 800px) {
// something that happens once the
// browser window is wider than 800px
}
Slide 395
// Default layout for skinniest devices
@media (min-width: 800px) {
// something that happens once the
// browser window is wider than 800px
}
Slide 396
@media (max-width: 800px) {
// something that only happens when the
// browser window is narrower than 800px
}
Slide 397
@media (max-width: 300px) { … }
@media (min-width: 300px) and
(max-width: 800px) { … }
@media (min-width: 800px) { … }
Slide 398
@media (min-height: 600px) { … }
Slide 399
Slide 400
Explicit Grid
vs
Implicit Grid
Slide 401
by Manuel Rego Casasnovas
http://blogs.igalia.com/mrego/2016/02/01/deep-dive-into-grid-layout-placement/
Slide 402
Slide 403
Slide 404
Slide 405
Slide 406
Slide 407
Slide 408
Slide 409
Slide 410
Slide 411
Slide 412
Slide 413
flex: initial;
(do not grow, do shrink)
flex: auto;
(grow and shrink)
flex: none;
(do not grow or shrink)
flex: <#>;
(distribute space by portions)
flex: 0 1 auto;
flex: 1 1 auto;
flex: 0 0 auto;
flex: <#> 1 0;
Slide 414
Slide 415
Slide 416
Slide 417
Slide 418
article {
max-width: 500px;
margin: 0 auto;
}
Slide 419
article {
column-count: 2;
column-gap: 2em;
}
Slide 420
Slide 421
article {
// column-count: 2;
column-width: 200px;
column-gap: 2em;
}
Slide 422
Slide 423
Slide 424
img {
width: 100%;
}
article {
column-width: 200px;
column-gap: 2em;
column-rule:
1px solid #444;
}
Slide 425
Slide 426