Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Let's Learn CSS Grid - FEDC
Search
Tim Smith
April 27, 2018
Design
0
130
Let's Learn CSS Grid - FEDC
Tim Smith
April 27, 2018
Tweet
Share
More Decks by Tim Smith
See All by Tim Smith
Let’s Learn CSS Grid - EE Conf
ttimsmith
1
180
Let's Learn CSS Grid - BeerCityCode
ttimsmith
2
190
Let's Learn CSS Grid
ttimsmith
1
310
Become a Better Designer with Side Projects - Blend Conf
ttimsmith
6
520
Become a Better Designer with Side Projects
ttimsmith
5
770
Work to Live, Don't Live to Work
ttimsmith
0
350
Other Decks in Design
See All in Design
なぜデフォルトが青色!? Tint Colorの理由に迫る
akidon0000
0
440
Credence
lratmansunu
0
380
Haruki_Konaka_Portforio.pdf
haruki556
0
550
DMMデザイン組織の生成AI導入プロセス - Adobe Fireflyと振り返る約1年とこれから -
takumasaito
1
330
地図・デザイン・可視化 −情報をわかりやすく伝えるために−
hjmkth
1
460
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
130
Карта реализации историй — убийца USM
ashapiro
0
160
【Designship 2024|10.13】デザイン組織を進化させるための仕組み化の要諦
payatsusan213
1
490
Картирование процесса фасилитация стратсессий с Картой гипотез при помощи Карты процесса-опыта
ashapiro
0
390
デザインからアプリ実装まで一貫したデザインシステムを構築するベストプラクティス
shuzo
13
5.8k
シームレスな連携を実現するデザイントークンの設計と構築
amishiratori
0
320
Tataki Ryu
olgastoryboard
0
140
Featured
See All Featured
A better future with KSS
kneath
238
17k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
4 Signs Your Business is Dying
shpigford
180
21k
Fireside Chat
paigeccino
32
3k
Designing for Performance
lara
604
68k
Speed Design
sergeychernyshev
24
570
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Automating Front-end Workflow
addyosmani
1365
200k
We Have a Design System, Now What?
morganepeng
50
7.2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
Become a Pro
speakerdeck
PRO
24
5k
Transcript
LET’S LEARN CSSGRID
Hi there! I’m Tim Smith
None
YouTube Channel youtube.com/smithtimmytim
Thank You
Agenda
Agenda 1. Problems we’ve had with layout
Agenda 1. Problems we’ve had with layout 2. What is
CSS Grid and how does it solve these problems?
Agenda 1. Problems we’ve had with layout 2. What is
CSS Grid and how does it solve these problems? 3. Why do I need to learn this?
Agenda 1. Problems we’ve had with layout 2. What is
CSS Grid and how does it solve these problems? 3. Why do I need to learn this? 4. Resources
A History of Layout Issues
Floats
Floats Suck
CSS Frameworks
CSS Frameworks <div class="small-12 medium-6 large-8"></div>
Separation of Concerns
Floats Aren’t Bad
They’re Not for Complex Layouts
Why?
None
Flexbox
Flexbox is Flexible
Main Column and Sidebar Layout <aside>Aside</aside> <main>Main Content</main>
Main Column and Sidebar Layout <aside>Aside</aside> <main>Main Content</main> And our
CSS.
Main Column and Sidebar Layout <aside>Aside</aside> <main>Main Content</main> And our
CSS. body { display: flex; } aside { background-color: #333; flex: 1 1 30%; } main { background-color: #333; flex: 1 1 70%; }
The two columns are completely flexible.
Flexbox Card Layout <ul class="boxes"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li>
</ul>
Flexbox Card Layout <ul class="boxes"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li>
</ul> And now our CSS.
Flexbox Card Layout <ul class="boxes"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li>
</ul> And now our CSS. .boxes { display: flex; flex-wrap: wrap; } .boxes li { flex: 1 1 30%; background: #333; margin: 0 .5rem 1rem; }
This is not what I want!
Math
You Need Stuff Like This li:nth-child(2n+2) { margin-right: 0; }
You Need Stuff Like This li:nth-child(2n+2) { margin-right: 0; }
Oh wait! What about bigger screens?
You Need Stuff Like This li:nth-child(2n+2) { margin-right: 0; }
Oh wait! What about bigger screens? @media screen and (min-width: 40em) { li:nth-child(2n+2) { margin-right: 1.5rem; } li:nth-child(3n+3) { margin-right: 0; } }
None
Flexbox Is Awesome
Vertical Align!
We’re Using Flexbox Wrong
CSS Grid to the Rescue
CSS Grid is Not a Float Killer
CSS Grid is Not a Flexbox Killer
You Don’t Need a Framework
CSS Grid Is the Framework
CSS Grid is Friendly
Great Use of Flexbox
Great Use of Floats
CSS Grid What Is It Good For?
“My super simple theory at the moment — if you
are putting widths on flex items, you are doing it wrong. Use Grid. (Let’s see if that holds.) —Jen Simmons
CSS Grid Basics
display: grid;
grid-template-columns
fr
grid-gap
Let’s See It in Action
Holy Grail Layout
Set Up <header>Header</header> <aside>Aside</aside> <main>Main Content</main> <footer>Footer</footer>
Set Up <header>Header</header> <aside>Aside</aside> <main>Main Content</main> <footer>Footer</footer> body { display:
grid; grid-template-columns: 2fr 3fr; grid-gap: 2rem; }
Let’s Place Our Items header { grid-column: 1 / span
2; } aside { grid-column-end: span 1; grid-row: 2; } main { grid-column: 2 / span 1; grid-row: 2; } footer { grid-column: 1 / span 2; grid-row: 3; }
Grid Lines
Rewrite with Grid Areas body { display: grid; grid-template-columns: 2fr
3fr; grid-gap: 2rem; grid-template-areas: "header header" "aside main" "footer footer"; } header { grid-area: header; } aside { grid-area: aside; } main { grid-area: main; } footer { grid-area: footer; }
None
What If? body { grid-template-areas: ". header" "aside main" ".
footer"; }
None
None
Easily Responsive body { display: grid; grid-gap: 2rem; grid-template-areas: "header"
"main" "aside" "footer"; } @media and screen (min-width: 40em) { body { grid-template-columns: 2fr 3fr; grid-template-areas: "header header" "aside main" "footer footer"; } }
None
Card Layout
Setup <ul class="boxes"> <li>Box 1</li> <li>Box 2</li> <li>Box 3</li> <li>Box
4</li> <li>Box 5</li> <li>Box 6</li> </ul>
Setup <ul class="boxes"> <li>Box 1</li> <li>Box 2</li> <li>Box 3</li> <li>Box
4</li> <li>Box 5</li> <li>Box 6</li> </ul> Now let’s get these puppies on a Grid.
Setup <ul class="boxes"> <li>Box 1</li> <li>Box 2</li> <li>Box 3</li> <li>Box
4</li> <li>Box 5</li> <li>Box 6</li> </ul> Now let’s get these puppies on a Grid. .boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); grid-gap: 1rem; }
Whoa! Hold Up.
Let’s Dissect This .boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px,
1fr)); grid-gap: 1rem; }
None
Mind. Blown.
Special Portfolio-Inspired Layout
Setup <ul class="portfolio"> <li>Item One</li> <li>Item Two</li> <li>Item Three</li> <li>Item
Four</li> <li>Item Five</li> </ul>
Setup <ul class="portfolio"> <li>Item One</li> <li>Item Two</li> <li>Item Three</li> <li>Item
Four</li> <li>Item Five</li> </ul> And setup our Grid container.
Setup <ul class="portfolio"> <li>Item One</li> <li>Item Two</li> <li>Item Three</li> <li>Item
Four</li> <li>Item Five</li> </ul> And setup our Grid container. .portfolio { display: grid; grid-auto-rows: minmax(100px, auto); grid-gap: 2px; grid-template-columns: repeat(6, 1fr); }
grid-auto-rows
Let’s Place Our Items .portfolio li:nth-child(1) { grid-column: 1 /
-1; } .portfolio li:nth-child(2) { grid-column: 1 / span 2; grid-row-end: span 3; } .portfolio li:nth-child(3) { grid-column: 3 / span 4; grid-row-end: span 2; } .portfolio li:nth-child(4), .portfolio li:nth-child(5) { grid-column: span 2; }
None
Holy Jack City, Batman
The Power of CSS Grid
None
The Time is Now
Simpler Code
New Amazing Layouts
I Delayed Learning Flexbox and Regret It
Feature Queries
Like This @supports (display:grid) { /* Grid CSS in here
*/ } @supports not (display:grid) { /* Fallback CSS here */ }
None
Browsers Ignore CSS They Don’t Understand
What Did We Learn?
1 CSS Grid Is Awesome
2 CSS Grid Is Friendly
3 Use CSS Grid Today
Only the Beginning
Rachel Andrew gridbyexample.com
Jen Simmons labs.jensimmons.com
Mozilla Developer Network developer.mozilla.org
Read The Spec w3.org/TR/css-grid-1/
Thanks! ttimsmith.com · @smithtimmytim