CSS Grid: Finally, True Layout Arrives version 5

Jen Kramer
Jen KramerAuthor, Speaker, Instructor at Harvard University Extension School & Freelance Web Design
C S S 4 G R I D : T R U E L A Y O U T
F I N A L L Y A R R I V E S
J E N K R A M E R
H A R V A R D U N I V E R S I T Y E X T E N S I O N S C H O O L
CSS Grid: Finally, True Layout Arrives version 5
https://www.w3.org/TR/css-2015/#css-levels
“There is no CSS Level 4… CSS the
language no longer has levels.”
https://www.w3.org/TR/html51/
CSS Grid: Finally, True Layout Arrives version 5
C S S 4 G R I D : T R U E L A Y O U T
F I N A L L Y A R R I V E S
J E N K R A M E R
H A R V A R D U N I V E R S I T Y E X T E N S I O N S C H O O L
X
https://www.github.com/jen4web/cssgrid
CSS Grid: Finally, True Layout Arrives version 5
CSS Grid: Finally, True Layout Arrives version 5
Time spent trying to get
the layout to work using
Flexbox, before giving up
and using floats
•  Defined by three characteristics
•  Flexible grid-based layout
•  Media queries (CSS3)
•  Images that resize
•  www.alistapart.com/articles/responsive-web-design/
R E S P O N S I V E D E S I G N
F L O A T S
P A R T 1
•  A hack from the start, right after table-based layout!
•  Features rows and cells.
•  Rows clear the floats on the cells.
•  Source ordering determines display, though some
(minor) rearrangement is possible.
•  Major disadvantage: equal column heights
F L O A T S
. R O W
C E L L /
. C O L - 1
C E L L /
. C O L - 1
C E L L /
. C O L - 1
C E L L /
. C O L - 1
<div class=“row”>
<div class=“col-1”></div>
<div class=“col-1”></div>
<div class=“col-1”></div>
<div class=“col-1”></div>
</div>
. R O W
C E L L /
. C O L - 1
C E L L /
. C O L - 1
C E L L /
. C O L - 1
C E L L /
. C O L - 1
.row::after {
content: "";
display: table;
clear: both;
}
.col-1 {
float: left;
margin-left: 4%;
width: 20%;
}
. R O W
C E L L /
. C O L - 1
C E L L /
. C O L - 1
C E L L /
. C O L - 1
C E L L /
. C O L - 1
@media only screen and (min-width: 480px)
and (max-width: 767px) {
.col-1 {
width: 44%;
}
}
R O W
C E L L /
. C O L - 1
C E L L /
. C O L - 1
C E L L /
. C O L - 1
C E L L /
. C O L - 1
@media only screen and
(max-width: 479px) {
.col-1 {
width: 98%;
margin: 1%;
float: none;
}
}
. R O W
C E L L /
. C O L - 1
1
C E L L /
. C O L - 1
2
C E L L /
. C O L - 1
3
C E L L /
. C O L - 1
4
There can be layout problems
with floats.
This can be resolved with
JavaScript, with a column
equalizer script.
/* rearranging the columns */
[class*="col-"] {
position: relative;
}
.col-push-1 {
left: 26%;
}
.col-pull-3 {
left: -74%;
}
F L E X B O X
P A R T 2
•  The first layout elements – but not designed to lay out
whole web pages
•  Features flex-containers (row) and flex-items (cells). Both are
required to work.
•  Excels at vertical centering and equal heights
•  Very easy to reorder boxes
•  Major disadvantages:
•  Wasn’t designed to be locked down for layouts! Works in
1 dimension only.
•  Browser support and syntax is challenging.
F L E X B O X
T H R E E V E R S I O N S O F F L E X B O X
•  2009: display: box;
•  2011: display: flexbox; (“tweener” syntax)
•  2016: display: flex;
•  Prefixing may still be required depending on
browser support desired
C U R R E N T S U P P O R T
•  Internet Explorer
•  <= IE 9: not supported
•  IE 10 supports “tweener” syntax (ms prefix)
•  IE 11, Edge: Full support (though buggy in IE 11)
•  Safari 7.1/8, iOS Safari 7/8 require webkit prefix
•  Others support current syntax (including Opera!)
•  http://caniuse.com/#feat=flexbox
<div class=“row”>
<div class=“col-1”></div>
<div class=“col-1”></div>
<div class=“col-1”></div>
<div class=“col-1”></div>
</div>
. R O W / C O N T A I N E R
I T E M /
. C O L - 1
I T E M /
. C O L - 1
I T E M /
. C O L - 1
I T E M /
. C O L - 1
.row {
display: flex;
flex: 0 1 auto;
flex-flow: row wrap;
justify-content: center;
margin: 1%;
}
Change flex-flow to other values to change
direction of rows – row reverse, column
reverse, no wrap
.col-1 includes:
flex: 0 0 24%; /* desktop */
flex: 0 0 48%; /* tablet */
flex: 0 0 98%; /* phone */
To change widths on .col-1, change the
flex-basis property. This is more flexible than
width.
/* rearranging the columns */
.col-push-1 {
order: 2;
}
.col-pull-3 {
order: 1;
}
C S S G R I D
F I N A L L Y !
•  Built into CSS specification (now a recommendation).
•  No “row” markup required.
•  Grid is designed to work in 2 dimensions.
•  Use Flexbox for UI elements, but use Grid for major
layout.
W H Y C S S G R I D ?
https://drafts.csswg.org/css-grid/
•  Full support: FF 52+, Chrome 57+, Safari 10.1+, Opera
44+ , iOS Safari 10.3+, Chrome for Android 59+,
Firefox for Android 59+
•  Partial support: IE 10, IE 11, Edge 12+, IE Mobile 10+
(these based on an older spec)
•  No support: Mostly mobile browsers (Opera Mini,
Opera Mobile, Blackberry, Android, etc)
•  http://caniuse.com/#search=grid
B R O W S E R S U P P O R T
•  Old spec:
https://github.com/codler/Grid-Layout-Polyfill
•  New spec:
https://github.com/FremyCompany/css-grid-polyfill/
•  @supports may help with all but IE browsers:
https://developer.mozilla.org/en-US/docs/Web/CSS/
@supports
P O L Y F I L L S
. W R A P P E R
C E L L /
. C O L - 1
C E L L /
. C O L - 2
C E L L /
. C O L - 3
C E L L /
. C O L - 4
<div class=“wrapper”>
<div class=“col-1”></div>
<div class=“col-2”></div>
<div class=“col-3”></div>
<div class=“col-4”></div>
</div>
. W R A P P E R
.wrapper {
display: grid;
grid-gap: 10px;
}
C E L L /
. C O L - 1
C E L L /
. C O L - 2
C E L L /
. C O L - 3
C E L L /
. C O L - 4
. W R A P P E R
.col-1 {
grid-column: 1 / 2;
}
.col-2 {
grid-column: 2 / 3;
}
.col-3 {
grid-column: 3 / 4;
}
C E L L /
. C O L - 1
C E L L /
. C O L - 2
C E L L /
. C O L - 3
C E L L /
. C O L - 41 2 3 4 5
.col-1 {
grid-column: 1 / 2;
grid-row: 1 / 3;
}
.col-2 {
grid-column: 2 / 3;
grid-row: 1 / 2;
}
.col-3 {
grid-column: 2 / 3;
grid-row: 2 / 3;
}
. W R A P P E R
C E L L /
. C O L - 1
C E L L /
. C O L - 2
C E L L /
. C O L - 3
•  Named grid template areas (header, footer, etc):
http://gridbyexample.com/examples/#example11
A L T E R N A T E S Y N T A X
. W R A P P E R
A S I D E
H E A D E R
A R T I C L E
R E O R D E R I N G
<div class=“wrapper”>
<header></header>
<article></article>
<aside></aside>
</div>
. W R A P P E R
A S I D E
H E A D E R
A R T I C L E
R E O R D E R I N G
Show code in GitHub!
reordering.html
reordering.css
https://github.com/jen4web/cssgrid
C O D E E X A M P L E
www.github.com/jen4web/cssgrid
•  CSS Tricks:
https://css-tricks.com/snippets/css/complete-guide-grid/
•  Grid by Example: http://gridbyexample.com/
•  Practical CSS Grid: Adding Grid to an Existing Design
https://alistapart.com/article/practical-grid
•  Basic concepts of grid layout
https://developer.mozilla.org/en-US/docs/Web/CSS/
CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout
•  CSS Grid Inspector (in Firefox):
https://developer.mozilla.org/en-US/docs/Tools/
Page_Inspector/How_to/Examine_grid_layouts
R E C O M M E N D E D R E S O U R C E S
•  Need browser support? Can’t go wrong with floats.
•  It’s time to learn Flexbox if you haven’t already. PS –
it’s in Bootstrap 4. Get used to it.
•  You can start using CSS Grid now, if used with browser
fallbacks.
•  Realistically, plan for another year before you use Grid
on most websites.
C U R R E N T R E C O M M E N D A T I O N S
Q U E S T I O N S ?
Jen Kramer
Arlington, MA, USA
Phone: 802-257-2657
jen@jenkramer.org
www.jenkramer.org
Twitter: @jen4web
Facebook: facebook.com/webdesignjen
1 of 42

Recommended

Which Responsive Design Framework is Best? by
Which Responsive Design Framework is Best?Which Responsive Design Framework is Best?
Which Responsive Design Framework is Best?Jen Kramer
327 views29 slides
Introduction to html 5 by
Introduction to html 5Introduction to html 5
Introduction to html 5Nir Elbaz
5.7K views104 slides
HTML5 & Friends by
HTML5 & FriendsHTML5 & Friends
HTML5 & FriendsRemy Sharp
16K views120 slides
Migrating a large scale banking app to compose by
Migrating a large scale banking app to composeMigrating a large scale banking app to compose
Migrating a large scale banking app to composeFatih Giris
316 views61 slides
The Future of the Web: HTML5 by
The Future of the Web: HTML5The Future of the Web: HTML5
The Future of the Web: HTML5Derek Bender
8.2K views33 slides
Rapid and Responsive - UX to Prototype with Bootstrap by
Rapid and Responsive - UX to Prototype with BootstrapRapid and Responsive - UX to Prototype with Bootstrap
Rapid and Responsive - UX to Prototype with BootstrapJosh Jeffryes
9.5K views39 slides

More Related Content

What's hot

关于 Html5 那点事 by
关于 Html5 那点事关于 Html5 那点事
关于 Html5 那点事Sofish Lin
938 views50 slides
Html5的应用与推行 by
Html5的应用与推行Html5的应用与推行
Html5的应用与推行Sofish Lin
756 views46 slides
[In Control 2010] HTML5 by
[In Control 2010] HTML5[In Control 2010] HTML5
[In Control 2010] HTML5Christopher Schmitt
1.6K views121 slides
Mind Your lang — Accessibility Camp Toronto 2016 by
Mind Your lang — Accessibility Camp Toronto 2016Mind Your lang — Accessibility Camp Toronto 2016
Mind Your lang — Accessibility Camp Toronto 2016Adrian Roselli
1.7K views48 slides
Facebook Development with Zend Framework by
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend FrameworkBrett Harris
5.5K views36 slides
Use atomic design ftw by
Use atomic design ftwUse atomic design ftw
Use atomic design ftwGiantJohnPepper
478 views52 slides

What's hot(20)

关于 Html5 那点事 by Sofish Lin
关于 Html5 那点事关于 Html5 那点事
关于 Html5 那点事
Sofish Lin938 views
Html5的应用与推行 by Sofish Lin
Html5的应用与推行Html5的应用与推行
Html5的应用与推行
Sofish Lin756 views
Mind Your lang — Accessibility Camp Toronto 2016 by Adrian Roselli
Mind Your lang — Accessibility Camp Toronto 2016Mind Your lang — Accessibility Camp Toronto 2016
Mind Your lang — Accessibility Camp Toronto 2016
Adrian Roselli1.7K views
Facebook Development with Zend Framework by Brett Harris
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend Framework
Brett Harris5.5K views
Web ninja html & css by Alfi Rizka
Web ninja   html & cssWeb ninja   html & css
Web ninja html & css
Alfi Rizka1.2K views
Even faster web sites by Felipe Lavín
Even faster web sitesEven faster web sites
Even faster web sites
Felipe Lavín1.2K views
Even faster web sites presentation 3 by Felipe Lavín
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
Felipe Lavín1.1K views
Is it time to start using HTML 5 by Ravi Raj
Is it time to start using HTML 5Is it time to start using HTML 5
Is it time to start using HTML 5
Ravi Raj3.3K views
Fringe Accessibility: A11y Camp Toronto 2015 by Adrian Roselli
Fringe Accessibility: A11y Camp Toronto 2015Fringe Accessibility: A11y Camp Toronto 2015
Fringe Accessibility: A11y Camp Toronto 2015
Adrian Roselli1.8K views
How to create a joomla component from scratch by Tim Plummer
How to create a joomla component from scratchHow to create a joomla component from scratch
How to create a joomla component from scratch
Tim Plummer40.2K views
HTML5 JS APIs by Remy Sharp
HTML5 JS APIsHTML5 JS APIs
HTML5 JS APIs
Remy Sharp47K views
BDD - Writing better scenario by Arnauld Loyer
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenario
Arnauld Loyer172.7K views
Scraping the web with Laravel, Dusk, Docker, and PHP by Paul Redmond
Scraping the web with Laravel, Dusk, Docker, and PHPScraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHP
Paul Redmond7.8K views
5 ways to embrace HTML5 today by Daniel Ryan
5 ways to embrace HTML5 today5 ways to embrace HTML5 today
5 ways to embrace HTML5 today
Daniel Ryan625 views
HTTP demystified for web developers by Peter Hilton
HTTP demystified for web developersHTTP demystified for web developers
HTTP demystified for web developers
Peter Hilton1K views

Similar to CSS Grid: Finally, True Layout Arrives version 5

CSS Grid: Finally, True Layout Arrives by
CSS Grid: Finally, True Layout ArrivesCSS Grid: Finally, True Layout Arrives
CSS Grid: Finally, True Layout ArrivesJen Kramer
864 views43 slides
CSS Grid: True Layout Finally Arrives by
CSS Grid: True Layout Finally ArrivesCSS Grid: True Layout Finally Arrives
CSS Grid: True Layout Finally ArrivesJen Kramer
1.3K views41 slides
CSS Grid: Finally, True Layout Arrives by
CSS Grid: Finally, True Layout ArrivesCSS Grid: Finally, True Layout Arrives
CSS Grid: Finally, True Layout ArrivesJen Kramer
707 views48 slides
Version 2: CSS4 Grid: True Layout Finally Arrives by
Version 2: CSS4 Grid: True Layout Finally ArrivesVersion 2: CSS4 Grid: True Layout Finally Arrives
Version 2: CSS4 Grid: True Layout Finally ArrivesJen Kramer
466 views40 slides
Design 4 Drupal Responsive Design 2.0 by
Design 4 Drupal Responsive Design 2.0Design 4 Drupal Responsive Design 2.0
Design 4 Drupal Responsive Design 2.0Jen Kramer
132 views31 slides
Responsive Design 2.0: The Death of Bootstrap by
Responsive Design 2.0: The Death of BootstrapResponsive Design 2.0: The Death of Bootstrap
Responsive Design 2.0: The Death of BootstrapJen Kramer
630 views27 slides

Similar to CSS Grid: Finally, True Layout Arrives version 5(20)

CSS Grid: Finally, True Layout Arrives by Jen Kramer
CSS Grid: Finally, True Layout ArrivesCSS Grid: Finally, True Layout Arrives
CSS Grid: Finally, True Layout Arrives
Jen Kramer864 views
CSS Grid: True Layout Finally Arrives by Jen Kramer
CSS Grid: True Layout Finally ArrivesCSS Grid: True Layout Finally Arrives
CSS Grid: True Layout Finally Arrives
Jen Kramer1.3K views
CSS Grid: Finally, True Layout Arrives by Jen Kramer
CSS Grid: Finally, True Layout ArrivesCSS Grid: Finally, True Layout Arrives
CSS Grid: Finally, True Layout Arrives
Jen Kramer707 views
Version 2: CSS4 Grid: True Layout Finally Arrives by Jen Kramer
Version 2: CSS4 Grid: True Layout Finally ArrivesVersion 2: CSS4 Grid: True Layout Finally Arrives
Version 2: CSS4 Grid: True Layout Finally Arrives
Jen Kramer466 views
Design 4 Drupal Responsive Design 2.0 by Jen Kramer
Design 4 Drupal Responsive Design 2.0Design 4 Drupal Responsive Design 2.0
Design 4 Drupal Responsive Design 2.0
Jen Kramer132 views
Responsive Design 2.0: The Death of Bootstrap by Jen Kramer
Responsive Design 2.0: The Death of BootstrapResponsive Design 2.0: The Death of Bootstrap
Responsive Design 2.0: The Death of Bootstrap
Jen Kramer630 views
Responsive Design 2.0: Flexbox, Grid, Calc, Custom Properties, and Sass by Jen Kramer
Responsive Design 2.0: Flexbox, Grid, Calc, Custom Properties, and SassResponsive Design 2.0: Flexbox, Grid, Calc, Custom Properties, and Sass
Responsive Design 2.0: Flexbox, Grid, Calc, Custom Properties, and Sass
Jen Kramer200 views
The New CSS Layout - Dutch PHP Conference by Rachel Andrew
The New CSS Layout - Dutch PHP ConferenceThe New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP Conference
Rachel Andrew2.6K views
Modern Layouts with CSS Grid, Flexbox, Calc, AND Custom Properties by Jen Kramer
Modern Layouts with CSS Grid, Flexbox, Calc, AND Custom PropertiesModern Layouts with CSS Grid, Flexbox, Calc, AND Custom Properties
Modern Layouts with CSS Grid, Flexbox, Calc, AND Custom Properties
Jen Kramer757 views
CSS4 Grid: True Layout Finally Arrives by Jen Kramer
CSS4 Grid: True Layout Finally ArrivesCSS4 Grid: True Layout Finally Arrives
CSS4 Grid: True Layout Finally Arrives
Jen Kramer1.6K views
CSS Grid layout - De volta para o futuro by Afonso Pacifer
CSS Grid layout - De volta para o futuroCSS Grid layout - De volta para o futuro
CSS Grid layout - De volta para o futuro
Afonso Pacifer703 views
But what about old browsers? by Rachel Andrew
But what about old browsers?But what about old browsers?
But what about old browsers?
Rachel Andrew851 views
Devoxx Belgium: CSS Grid Layout by Rachel Andrew
Devoxx Belgium: CSS Grid LayoutDevoxx Belgium: CSS Grid Layout
Devoxx Belgium: CSS Grid Layout
Rachel Andrew1.2K views
CSS Grid Layout by Rachel Andrew
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
Rachel Andrew128.2K views
The Home of the Future: CSS Layouts by Peter Gasston
The Home of the Future: CSS LayoutsThe Home of the Future: CSS Layouts
The Home of the Future: CSS Layouts
Peter Gasston2K views
CSS Day: CSS Grid Layout by Rachel Andrew
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
Rachel Andrew9.6K views
An Event Apart SF: CSS Grid Layout by Rachel Andrew
An Event Apart SF: CSS Grid LayoutAn Event Apart SF: CSS Grid Layout
An Event Apart SF: CSS Grid Layout
Rachel Andrew1.6K views
CSS Grid Layout for Topconf, Linz by Rachel Andrew
CSS Grid Layout for Topconf, LinzCSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, Linz
Rachel Andrew185K views

More from Jen Kramer

The Meta-Talk: Giving Outstanding Technical Presentations by
The Meta-Talk: Giving Outstanding Technical PresentationsThe Meta-Talk: Giving Outstanding Technical Presentations
The Meta-Talk: Giving Outstanding Technical PresentationsJen Kramer
129 views40 slides
5 Steps to Effective Planning for Your No-Code Website or App by
5 Steps to Effective Planning for Your No-Code Website or App5 Steps to Effective Planning for Your No-Code Website or App
5 Steps to Effective Planning for Your No-Code Website or AppJen Kramer
1K views28 slides
Best Practices When Moving Online in a Hurry by
Best Practices When Moving Online in a HurryBest Practices When Moving Online in a Hurry
Best Practices When Moving Online in a HurryJen Kramer
687 views16 slides
The Art of Honest Feedback by
The Art of Honest FeedbackThe Art of Honest Feedback
The Art of Honest FeedbackJen Kramer
224 views38 slides
The Accidental Web Designer by
The Accidental Web DesignerThe Accidental Web Designer
The Accidental Web DesignerJen Kramer
6.8K views46 slides
Design 4 Drupal Better than luck: Product building for idea people by
Design 4 Drupal Better than luck: Product building for idea people Design 4 Drupal Better than luck: Product building for idea people
Design 4 Drupal Better than luck: Product building for idea people Jen Kramer
256 views47 slides

More from Jen Kramer(20)

The Meta-Talk: Giving Outstanding Technical Presentations by Jen Kramer
The Meta-Talk: Giving Outstanding Technical PresentationsThe Meta-Talk: Giving Outstanding Technical Presentations
The Meta-Talk: Giving Outstanding Technical Presentations
Jen Kramer129 views
5 Steps to Effective Planning for Your No-Code Website or App by Jen Kramer
5 Steps to Effective Planning for Your No-Code Website or App5 Steps to Effective Planning for Your No-Code Website or App
5 Steps to Effective Planning for Your No-Code Website or App
Jen Kramer1K views
Best Practices When Moving Online in a Hurry by Jen Kramer
Best Practices When Moving Online in a HurryBest Practices When Moving Online in a Hurry
Best Practices When Moving Online in a Hurry
Jen Kramer687 views
The Art of Honest Feedback by Jen Kramer
The Art of Honest FeedbackThe Art of Honest Feedback
The Art of Honest Feedback
Jen Kramer224 views
The Accidental Web Designer by Jen Kramer
The Accidental Web DesignerThe Accidental Web Designer
The Accidental Web Designer
Jen Kramer6.8K views
Design 4 Drupal Better than luck: Product building for idea people by Jen Kramer
Design 4 Drupal Better than luck: Product building for idea people Design 4 Drupal Better than luck: Product building for idea people
Design 4 Drupal Better than luck: Product building for idea people
Jen Kramer256 views
5 Best Practices for Teaching UX in Corporate and Academic Environments by Jen Kramer
5 Best Practices for Teaching UX in Corporate and Academic Environments5 Best Practices for Teaching UX in Corporate and Academic Environments
5 Best Practices for Teaching UX in Corporate and Academic Environments
Jen Kramer321 views
The Meta-talk: Giving Outstanding Technical Presentations by Jen Kramer
The Meta-talk: Giving Outstanding Technical PresentationsThe Meta-talk: Giving Outstanding Technical Presentations
The Meta-talk: Giving Outstanding Technical Presentations
Jen Kramer395 views
Jen Kramer's Harvard Commendation Letters by Jen Kramer
Jen Kramer's Harvard Commendation LettersJen Kramer's Harvard Commendation Letters
Jen Kramer's Harvard Commendation Letters
Jen Kramer327 views
Jen Kramer's CV, June 29, 2018 by Jen Kramer
Jen Kramer's CV, June 29, 2018Jen Kramer's CV, June 29, 2018
Jen Kramer's CV, June 29, 2018
Jen Kramer294 views
How to give a great technical talk by Jen Kramer
How to give a great technical talkHow to give a great technical talk
How to give a great technical talk
Jen Kramer142 views
Battling the Blah-Blah-Blahs: 7 Tips for Making Websites Readable by Jen Kramer
Battling the Blah-Blah-Blahs: 7 Tips for Making Websites ReadableBattling the Blah-Blah-Blahs: 7 Tips for Making Websites Readable
Battling the Blah-Blah-Blahs: 7 Tips for Making Websites Readable
Jen Kramer277 views
What They Don't Teach You in Class: How to Become a Web Freelancer by Jen Kramer
What They Don't Teach You in Class: How to Become a Web FreelancerWhat They Don't Teach You in Class: How to Become a Web Freelancer
What They Don't Teach You in Class: How to Become a Web Freelancer
Jen Kramer184 views
Big C in CSS: The Cascade by Jen Kramer
Big C in CSS: The CascadeBig C in CSS: The Cascade
Big C in CSS: The Cascade
Jen Kramer314 views
Identifying Successful Websites by Jen Kramer
Identifying Successful WebsitesIdentifying Successful Websites
Identifying Successful Websites
Jen Kramer641 views
The Big C in CSS by Jen Kramer
The Big C in CSSThe Big C in CSS
The Big C in CSS
Jen Kramer491 views
Creating Great Content for Websites by Jen Kramer
Creating Great Content for WebsitesCreating Great Content for Websites
Creating Great Content for Websites
Jen Kramer185 views
Freelancing Tips by Jen Kramer
Freelancing TipsFreelancing Tips
Freelancing Tips
Jen Kramer387 views
Flexbox: Coming to a Browser Near You by Jen Kramer
Flexbox: Coming to a Browser Near YouFlexbox: Coming to a Browser Near You
Flexbox: Coming to a Browser Near You
Jen Kramer10.3K views
Up and Running with Bootstrap 4 by Jen Kramer
Up and Running with Bootstrap 4Up and Running with Bootstrap 4
Up and Running with Bootstrap 4
Jen Kramer11.8K views

Recently uploaded

Optimizing Communication to Optimize Human Behavior - LCBM by
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBMYaman Kumar
38 views49 slides
AI + Memoori = AIM by
AI + Memoori = AIMAI + Memoori = AIM
AI + Memoori = AIMMemoori
14 views9 slides
The Coming AI Tsunami.pptx by
The Coming AI Tsunami.pptxThe Coming AI Tsunami.pptx
The Coming AI Tsunami.pptxjohnhandby
13 views12 slides
The Power of Heat Decarbonisation Plans in the Built Environment by
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built EnvironmentIES VE
84 views20 slides
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Moses Kemibaro
35 views38 slides
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsPriyanka Aash
162 views59 slides

Recently uploaded(20)

Optimizing Communication to Optimize Human Behavior - LCBM by Yaman Kumar
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBM
Yaman Kumar38 views
AI + Memoori = AIM by Memoori
AI + Memoori = AIMAI + Memoori = AIM
AI + Memoori = AIM
Memoori14 views
The Coming AI Tsunami.pptx by johnhandby
The Coming AI Tsunami.pptxThe Coming AI Tsunami.pptx
The Coming AI Tsunami.pptx
johnhandby13 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE84 views
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro35 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash162 views
Innovation & Entrepreneurship strategies in Dairy Industry by PervaizDar1
Innovation & Entrepreneurship strategies in Dairy IndustryInnovation & Entrepreneurship strategies in Dairy Industry
Innovation & Entrepreneurship strategies in Dairy Industry
PervaizDar135 views
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 views
GDSC GLAU Info Session.pptx by gauriverrma4
GDSC GLAU Info Session.pptxGDSC GLAU Info Session.pptx
GDSC GLAU Info Session.pptx
gauriverrma415 views
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... by BookNet Canada
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
BookNet Canada41 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue108 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays36 views
"Node.js Development in 2024: trends and tools", Nikita Galkin by Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays33 views
The Power of Generative AI in Accelerating No Code Adoption.pdf by Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf
Saeed Al Dhaheri39 views
This talk was not generated with ChatGPT: how AI is changing science by Elena Simperl
This talk was not generated with ChatGPT: how AI is changing scienceThis talk was not generated with ChatGPT: how AI is changing science
This talk was not generated with ChatGPT: how AI is changing science
Elena Simperl32 views

CSS Grid: Finally, True Layout Arrives version 5

  • 1. C S S 4 G R I D : T R U E L A Y O U T F I N A L L Y A R R I V E S J E N K R A M E R H A R V A R D U N I V E R S I T Y E X T E N S I O N S C H O O L
  • 3. https://www.w3.org/TR/css-2015/#css-levels “There is no CSS Level 4… CSS the language no longer has levels.”
  • 6. C S S 4 G R I D : T R U E L A Y O U T F I N A L L Y A R R I V E S J E N K R A M E R H A R V A R D U N I V E R S I T Y E X T E N S I O N S C H O O L X https://www.github.com/jen4web/cssgrid
  • 9. Time spent trying to get the layout to work using Flexbox, before giving up and using floats
  • 10. •  Defined by three characteristics •  Flexible grid-based layout •  Media queries (CSS3) •  Images that resize •  www.alistapart.com/articles/responsive-web-design/ R E S P O N S I V E D E S I G N
  • 11. F L O A T S P A R T 1
  • 12. •  A hack from the start, right after table-based layout! •  Features rows and cells. •  Rows clear the floats on the cells. •  Source ordering determines display, though some (minor) rearrangement is possible. •  Major disadvantage: equal column heights F L O A T S
  • 13. . R O W C E L L / . C O L - 1 C E L L / . C O L - 1 C E L L / . C O L - 1 C E L L / . C O L - 1 <div class=“row”> <div class=“col-1”></div> <div class=“col-1”></div> <div class=“col-1”></div> <div class=“col-1”></div> </div>
  • 14. . R O W C E L L / . C O L - 1 C E L L / . C O L - 1 C E L L / . C O L - 1 C E L L / . C O L - 1 .row::after { content: ""; display: table; clear: both; } .col-1 { float: left; margin-left: 4%; width: 20%; }
  • 15. . R O W C E L L / . C O L - 1 C E L L / . C O L - 1 C E L L / . C O L - 1 C E L L / . C O L - 1 @media only screen and (min-width: 480px) and (max-width: 767px) { .col-1 { width: 44%; } }
  • 16. R O W C E L L / . C O L - 1 C E L L / . C O L - 1 C E L L / . C O L - 1 C E L L / . C O L - 1 @media only screen and (max-width: 479px) { .col-1 { width: 98%; margin: 1%; float: none; } }
  • 17. . R O W C E L L / . C O L - 1 1 C E L L / . C O L - 1 2 C E L L / . C O L - 1 3 C E L L / . C O L - 1 4 There can be layout problems with floats. This can be resolved with JavaScript, with a column equalizer script.
  • 18. /* rearranging the columns */ [class*="col-"] { position: relative; } .col-push-1 { left: 26%; } .col-pull-3 { left: -74%; }
  • 19. F L E X B O X P A R T 2
  • 20. •  The first layout elements – but not designed to lay out whole web pages •  Features flex-containers (row) and flex-items (cells). Both are required to work. •  Excels at vertical centering and equal heights •  Very easy to reorder boxes •  Major disadvantages: •  Wasn’t designed to be locked down for layouts! Works in 1 dimension only. •  Browser support and syntax is challenging. F L E X B O X
  • 21. T H R E E V E R S I O N S O F F L E X B O X •  2009: display: box; •  2011: display: flexbox; (“tweener” syntax) •  2016: display: flex; •  Prefixing may still be required depending on browser support desired
  • 22. C U R R E N T S U P P O R T •  Internet Explorer •  <= IE 9: not supported •  IE 10 supports “tweener” syntax (ms prefix) •  IE 11, Edge: Full support (though buggy in IE 11) •  Safari 7.1/8, iOS Safari 7/8 require webkit prefix •  Others support current syntax (including Opera!) •  http://caniuse.com/#feat=flexbox
  • 23. <div class=“row”> <div class=“col-1”></div> <div class=“col-1”></div> <div class=“col-1”></div> <div class=“col-1”></div> </div> . R O W / C O N T A I N E R I T E M / . C O L - 1 I T E M / . C O L - 1 I T E M / . C O L - 1 I T E M / . C O L - 1
  • 24. .row { display: flex; flex: 0 1 auto; flex-flow: row wrap; justify-content: center; margin: 1%; } Change flex-flow to other values to change direction of rows – row reverse, column reverse, no wrap
  • 25. .col-1 includes: flex: 0 0 24%; /* desktop */ flex: 0 0 48%; /* tablet */ flex: 0 0 98%; /* phone */ To change widths on .col-1, change the flex-basis property. This is more flexible than width.
  • 26. /* rearranging the columns */ .col-push-1 { order: 2; } .col-pull-3 { order: 1; }
  • 27. C S S G R I D F I N A L L Y !
  • 28. •  Built into CSS specification (now a recommendation). •  No “row” markup required. •  Grid is designed to work in 2 dimensions. •  Use Flexbox for UI elements, but use Grid for major layout. W H Y C S S G R I D ?
  • 30. •  Full support: FF 52+, Chrome 57+, Safari 10.1+, Opera 44+ , iOS Safari 10.3+, Chrome for Android 59+, Firefox for Android 59+ •  Partial support: IE 10, IE 11, Edge 12+, IE Mobile 10+ (these based on an older spec) •  No support: Mostly mobile browsers (Opera Mini, Opera Mobile, Blackberry, Android, etc) •  http://caniuse.com/#search=grid B R O W S E R S U P P O R T
  • 31. •  Old spec: https://github.com/codler/Grid-Layout-Polyfill •  New spec: https://github.com/FremyCompany/css-grid-polyfill/ •  @supports may help with all but IE browsers: https://developer.mozilla.org/en-US/docs/Web/CSS/ @supports P O L Y F I L L S
  • 32. . W R A P P E R C E L L / . C O L - 1 C E L L / . C O L - 2 C E L L / . C O L - 3 C E L L / . C O L - 4 <div class=“wrapper”> <div class=“col-1”></div> <div class=“col-2”></div> <div class=“col-3”></div> <div class=“col-4”></div> </div>
  • 33. . W R A P P E R .wrapper { display: grid; grid-gap: 10px; } C E L L / . C O L - 1 C E L L / . C O L - 2 C E L L / . C O L - 3 C E L L / . C O L - 4
  • 34. . W R A P P E R .col-1 { grid-column: 1 / 2; } .col-2 { grid-column: 2 / 3; } .col-3 { grid-column: 3 / 4; } C E L L / . C O L - 1 C E L L / . C O L - 2 C E L L / . C O L - 3 C E L L / . C O L - 41 2 3 4 5
  • 35. .col-1 { grid-column: 1 / 2; grid-row: 1 / 3; } .col-2 { grid-column: 2 / 3; grid-row: 1 / 2; } .col-3 { grid-column: 2 / 3; grid-row: 2 / 3; } . W R A P P E R C E L L / . C O L - 1 C E L L / . C O L - 2 C E L L / . C O L - 3
  • 36. •  Named grid template areas (header, footer, etc): http://gridbyexample.com/examples/#example11 A L T E R N A T E S Y N T A X
  • 37. . W R A P P E R A S I D E H E A D E R A R T I C L E R E O R D E R I N G <div class=“wrapper”> <header></header> <article></article> <aside></aside> </div>
  • 38. . W R A P P E R A S I D E H E A D E R A R T I C L E R E O R D E R I N G Show code in GitHub! reordering.html reordering.css https://github.com/jen4web/cssgrid
  • 39. C O D E E X A M P L E www.github.com/jen4web/cssgrid
  • 40. •  CSS Tricks: https://css-tricks.com/snippets/css/complete-guide-grid/ •  Grid by Example: http://gridbyexample.com/ •  Practical CSS Grid: Adding Grid to an Existing Design https://alistapart.com/article/practical-grid •  Basic concepts of grid layout https://developer.mozilla.org/en-US/docs/Web/CSS/ CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout •  CSS Grid Inspector (in Firefox): https://developer.mozilla.org/en-US/docs/Tools/ Page_Inspector/How_to/Examine_grid_layouts R E C O M M E N D E D R E S O U R C E S
  • 41. •  Need browser support? Can’t go wrong with floats. •  It’s time to learn Flexbox if you haven’t already. PS – it’s in Bootstrap 4. Get used to it. •  You can start using CSS Grid now, if used with browser fallbacks. •  Realistically, plan for another year before you use Grid on most websites. C U R R E N T R E C O M M E N D A T I O N S
  • 42. Q U E S T I O N S ? Jen Kramer Arlington, MA, USA Phone: 802-257-2657 jen@jenkramer.org www.jenkramer.org Twitter: @jen4web Facebook: facebook.com/webdesignjen