SlideShare a Scribd company logo
1 of 146
Download to read offline
New CSS Layout Meets the Real World
Rachel Andrew @ An Event Apart Seattle
“The state of the use of Cascading Style Sheet on the web is really
beginning to get boring. Why haven't designers begun exploiting
its benefits yet?”
I can remember a time not too long ago when individuals were
running amok exploiting the simplest of html tags and creating
works of beauty. But now, after browser vendors have stepped
it up and given us much of the control we've been asking for, I
can't seem to find web designers that are exploiting these new
found powers.
I can remember a time not too long ago when individuals were
running amok exploiting the simplest of html tags and creating
works of beauty. But now, after browser vendors have stepped
it up and given us much of the control we've been asking for, I
can't seem to find web designers that are exploiting these new
found powers.
Chris Casciano
2nd October 2001
Chris Casciano
http://www.chunkysoup.net/opinion/boringcss/
www.glish.com/css
www.thenoodleincident.com/tutorials/box_lesson/boxes.html
16 Years.
March 2017
March 2017 March 2017 March 2017 March 2017 March 2017 Soooooon!
caniuse.com/#feat=css-grid
But, old
browsers!
There will be
code
A new system
for layout
Featuring
▸ Flexbox
▸ CSS Grid Layout
▸ Box Alignment
▸ CSS Shapes
▸ CSS Feature Queries
fractal.build/
The Media
Object
New CSS Meets
Media Object
▸ contains an image plus content
▸ is flexible
▸ elements should stack on mobile
▸ box should clear the contents
▸ image can be to the left or the right
▸ can be nested
Avoid pre-empting the
need for markup as
styling hooks.
<div class="media">
<h2 class="title">This is my title</
h2>
<div class="img">
<img src="/assets/img/
placeholder.jpg" alt="Placeholder">
</div>
<div class="content">
</div>
<div class="footer">
footer here
</div>
</div>
Media Object
A parent with a class of ‘media’
Four child elements:
- title
- img
- content
- footer
@media (min-width: 600px) {
.media {
display: grid;
}
}
Media Object
To create a grid use a new value of
the display property:
display: grid
@media (min-width: 600px) {
.media {
display: grid;
grid-column-gap: 20px;
}
}
Media Object
Create gutters between grid cells:
- grid-column-gap
- grid-row-gap
- grid-gap
@media (min-width: 600px) {
.media {
display: grid;
grid-column-gap: 20px;
grid-template-columns: 1fr 3fr;
}
}
Media Object
The grid-template-columns property
creates column tracks on the grid.
The new fr unit represents a fraction
of the available space.
.media > .title {
grid-area: title;
}
.media > .img {
grid-area: img;
}
.media > .content {
grid-area: bd;
}
.media > .footer {
grid-area: ft;
}
Media Object
Define areas with grid-area
@media (min-width: 600px) {
.media {
display: grid;
grid-column-gap: 20px;
grid-template-columns: 1fr 3fr;
grid-template-areas:
"img title"
"img bd"
"img ft";
}
}
Media Object
Describing layout with the 

grid-template-areas property
img
img
img
title
bd
ft
auto
<div class="flex-example">
<div class="one">Box one</div>
<div class="two">Box two</div>
<div class="three">
<div class="inner">Box three</div>
</div>
</div>
auto as flex-basis
Box one, two and three are nested
inside flex-example.
There is another element nested
inside box three.
.flex-example {
display: flex;
}
.flex-example > div {
flex: 1 1 auto;
}
auto as flex-basis
The parent becomes a flex container,
and all direct children are set to grow
and shrink from a flex-basis of auto.
no box has a width, and flex-basis is auto and so resolved from the content
.flex-example {
display: flex;
}
.flex-example > div {
flex: 1 1 auto;
}
.two {
width: 350px;
}
.three .inner {
width: 200px;
}
auto as flex-basis
Use auto and the flex-basis will be
taken from any width set on the item.
If there is no width, flex-basis will be
taken from the content width.
width 350px nested item width 200pxno width
https://cssgrid.me/flex-auto
@media (min-width: 600px) {
.media {
display: grid;
grid-column-gap: 20px;
grid-template-columns: 1fr 3fr;
grid-template-rows: auto 1fr;
grid-template-areas:
"img title"
"img bd"
"img ft";
}
}
Media Object
The grid-template-rows property
defines the rows on the grid.
If we don’t define rows grid will
create them as part of the implicit
grid.
@media (min-width: 600px) {
.media {
display: grid;
grid-column-gap: 20px;
grid-template-columns: 150px 1fr;
grid-template-rows: auto 1fr;
grid-template-areas:
"img title"
"img bd"
"img ft";
}
}
Media Object
Mix absolute lengths with fr units to
have flexible containers that have
some fixed width tracks.
Media Object
▸ contains an image plus content ✓
▸ is flexible ✓
▸ elements should stack on mobile ✓
▸ box should clear the contents ✓
▸ image can be to the left or the right
▸ can be nested
@media (min-width: 600px) {
.media {
display: grid;
grid-column-gap: 20px;
grid-template-columns: 150px 1fr;
grid-template-rows: auto 1fr;
grid-template-areas:
"img title"
"img bd"
"img ft";
}
.media.media-flip {
grid-template-columns: 1fr 150px;
grid-template-areas:
"title img"
"bd img"
"ft img";
}
}
Media Object
Flipping the display by creating new
rules for the ‘media-flip’ class.
Media Object
▸ contains an image plus content ✓
▸ is flexible ✓
▸ elements should stack on mobile ✓
▸ box should clear the contents ✓
▸ image can be to the left or the right ✓
▸ can be nested
.media > .media {
grid-column: 2 / -1 ;
}
Media Object
If an item with a class of media is the
direct child of an item with a class of
media, start on column line 2.
Line -1 is the final line of the grid.
Media Object
▸ contains an image plus content ✓
▸ is flexible ✓
▸ elements should stack on mobile ✓
▸ box should clear the contents ✓
▸ image can be to the left or the right ✓
▸ can be nested ✓
Magazine
style layout
New CSS Meets
<figure class=“feature-fig">
<figcaption>caption</figcaption>
<img src="placeholder1.jpg" alt="placeholder 1">
<img src="placeholder1.jpg" alt="placeholder 2">
<img src="placeholder1.jpg" alt="placeholder 3">
</figure>
Magazine Style Layout
The block is a figure with three
images and a caption.
<div class="half-border">
<p class="inner">Content here</p>
</div>
Half-border Box
Creating the half-border box as a
standalone pattern.
.half-border {
display: grid;
border-top: 2px solid #000;
grid-template-rows:
minmax(30px, 1fr) 2fr;
}
Half-border Box
I’m using grid layout to create a single
column, 2 row grid.
minmax()
1fr 1fr 1fr
1fr 1frminmax(400px, 1fr)
700px container
300px height
1fr
50px
minmax(50px, 1fr)
https://cssgrid.me/grid-minmax
.half-border {
display: grid;
border-top: 2px solid #000;
grid-template-rows:
minmax(30px, 1fr) 2fr;
align-self: start;
}
Half-border Box
The first row of the grid is a minimum
of 30px tall, a maximum of 1fr.
.half-border::before {
content: "";
border-left: 2px solid #000;
grid-row: 1;
grid-column: 1;
}
Half-border Box
A pseudo-element created with
generated content will also become a
grid item.
.half-border .inner {
grid-row: 1 / 3;
grid-column: 1;
margin: 10px;
}
Half-border Box
The inner starts at row line 1 and
ends at row line 3, spanning 2 row
tracks.
<figure class="feature-fig">
<figcaption class="half-border">
<p class="inner">caption</p>
</figcaption>
<img src="placeholder1.jpg" alt="placeholder 1">
<img src="placeholder1.jpg" alt="placeholder 2">
<img src="placeholder1.jpg" alt="placeholder 3">
</figure>
Magazine Style Layout
Adding the half-border classes.
@media (min-width: 600px) {
.feature-fig {
display: grid;
grid-template-columns: 2fr 2fr 1fr;
}
.feature-fig img {
object-fit: cover;
}
}
Magazine Style Layout
Defining a grid with 3 column tracks.
@media (min-width: 600px) {
.feature-fig {
display: grid;
grid-template-columns: 2fr 2fr 1fr;
grid-template-rows:
minmax(200px, auto)
minmax(100px, auto)
auto
minmax(100px,auto);
}
.feature-fig img {
object-fit: cover;
}
}
Magazine Style Layout
Creating row tracks. The minmax()
notation means that we can set a
minimum size for the tracks.
.feature-fig figcaption {
grid-column: 1;
grid-row: 3;
margin-top: 10px;
}
Magazine Style Layout
Position the figcaption after grid
column line 1, and grid row line 3
.feature-fig .main {
grid-row: 1 / 3;
grid-column: 1 / 3;
z-index: 2;
}
.feature-fig .insert {
grid-row: 2 / 5;
grid-column: 2 / 4;
border-top: 10px solid #fff;
border-left: 10px solid #fff;
z-index: 3;
}
.feature-fig .small {
grid-row: 4 / 6;
grid-column: 1 ;
}
Magazine Style Layout
The items are positioned using line-
based positioning.
Grid items respect z-index so we can
layer items that end up in the same
cells.
.photo-circle {
border-radius: 50%;
}
Magazine Style Layout
Setting border-radius to 50% gives us
a circle.
Fancy headers
with circles
New CSS Meets
<header class="run-header">
<h1>
4.5
Miles
in Berlin,
Germany</h1>
<div class="intro">
<p> </p>
</div>
</header>
Fancy Header
The mark-up for the article header
<header class="run-header">
<h1><span class="distance-wrap">
<span class="distance">4.5</span>
<span class="miles">Miles</span></
span>
<span class="location">in Berlin,
Germany</span></h1>
<div class="intro">
<p> </p>
</div>
</header>
Fancy Header
We need to add some mark-up to
identify the parts of the h1 text we
want to style.
.run-header .distance-wrap {
border-radius: 50%;
width: 5em;
height: 5em;
padding: 0;
background: linear-
gradient(rgba(0,0,0,0),
rgba(0,0,0,0.8)),url(/assets/img/flag-
germany.jpg) center center;
background-size: cover;
margin: 0 auto 1em auto;
z-index: 2;
}
Fancy Header
I use border-radius set to 50% to
make the distance part of the header
a circle.
.run-header .distance-wrap {
display: block;
border-radius: 50%;
width: 5em;
height: 5em;
padding: 0;
background: linear-
gradient(rgba(0,0,0,0),
rgba(0,0,0,0.8)),url(/assets/img/flag-
germany.jpg) center center;
background-size: cover;
margin: 0 auto 1em auto;
z-index: 2;
}
Fancy Header
Setting display to block will mean the
span becomes block level.
.run-header .distance-wrap {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border-radius: 50%;
width: 5em;
height: 5em;
padding: 0;
background: linear-
gradient(rgba(0,0,0,0),
rgba(0,0,0,0.8)),url(/assets/img/flag-
germany.jpg) center center;
background-size: cover;
margin: 0 auto 1em auto;
z-index: 2;
}
Fancy Header
I use border-radius set to 50% to
make the distance part of the header
a circle.
@media (min-width: 600px) {
.run-header .distance-wrap {
float: left;
margin: 0 10px 10px 0;
}
.run-header h1 {
text-align: left;
width: 100%;
}
.run-header .location {
display: inline-block;
padding-left: 1em;
margin-left: -1em;
}
.intro {
padding: 0;
}
}
Fancy Header
Floating the distance-wrap class left
means the location comes up
alongside it.
@media (min-width: 600px) {
.run-header .distance-wrap {
float: left;
margin: 0 10px 10px 0;
}
.run-header h1 {
text-align: left;
width: 100%;
}
.run-header .location {
display: inline-block;
padding-left: 1em;
margin-left: -1em;
}
.intro {
padding: 0;
}
}
Fancy Header
We can use the shape-outside
property with a value of margin-box
to create the curved text.
@media (min-width: 600px) {
.run-header .distance-wrap {
float: left;
shape-outside: margin-box;
margin: 0 10px 10px 0;
}
.run-header h1 {
text-align: left;
width: 100%;
}
.run-header .location {
display: inline-block;
padding-left: 1em;
margin-left: -1em;
}
.intro {
padding: 0;
}
}
Fancy Header
We can use the shape-outside
property with a value of margin-box
to create the curved text.
Design for the extreme
edges of the experience.
The middle is
constantly changing.
caniuse.com/#feat=css-shapes
CSS has backwards
compatibility built in.
Feature Queries
caniuse.com/#feat=css-featurequeries
@supports (shape-outside: margin-box) {
}
Fancy Header
A Feature Query looks very similar to
Media Queries. Here we test for a
property and value pair.
Using Feature Queries
▸ Write CSS for browsers without support
▸ Override those properties inside the feature queries
▸ See https://hacks.mozilla.org/2016/08/using-feature-queries-in-css/
▸ A component based approach helps to keep this all in check!
.intro {
padding: 0;
margin-left: 9em;
}
@supports (shape-outside: margin-box) {
.run-header .distance-wrap {
shape-outside: margin-box;
margin: 0 10px 10px 0;
}
.intro {
margin-left: 0;
}
}
Fancy Header
Outside of the feature query I add a
left margin to the intro.
Inside the feature query we add the
shape-outside property and also
remove that margin.
Fancy Header three ways - https://cssgrid.me/fancy-headers
@supports(display: grid) {
}
Half-border Box
Using a Feature Query to check for
Grid Layout support
.half-border {
display: inline-block;
border: 2px solid #000;
padding: 10px;
}
@supports(display: grid) {
.half-border {
border: 0;
padding: 0;
/* the rest of my CSS for grid */
}
}
Half-border Box
Outside the Feature Query write CSS
to style the box.
Override that for Grid supporting
browsers inside the query.
https://cssgrid.me/half-border-box
@media (min-width: 600px) {
.half-border {
width: 45%;
display: inline-block;
vertical-align: top;
}
.feature-fig img {
object-fit: cover;
display: inline-block;
width: 45%;
}
.feature-fig .small {
vertical-align: bottom;
margin: 0 0 20px 5%;
}
.photo-circle {
border-radius: 50%;
}
@supports(display: grid) {
.feature-fig img,
.half-border {
width: auto;
}
.feature-fig .small {
margin: 0;
}
/* the rest of my CSS for grid */
}
}
Magazine Style Layout
Outside the Feature Query add CSS
for non-grid browsers.
Inside write CSS to override plus the
rules for grid layout.
@media (min-width: 600px) {
.half-border {
width: 45%;
display: inline-block;
vertical-align: top;
}
.feature-fig img {
object-fit: cover;
display: inline-block;
width: 45%;
}
.feature-fig .small {
vertical-align: bottom;
margin: 0 0 20px 5%;
}
.photo-circle {
border-radius: 50%;
}
@supports(display: grid) {
.feature-fig img,
.half-border {
width: auto;
}
.feature-fig .small {
margin: 0;
}
/* the rest of my CSS for grid */
}
}
Magazine Style Layout
Outside the Feature Query add CSS
for non-grid browsers.
Inside write CSS to override plus the
rules for grid layout.
If using display: grid or display: flex
▸ Floated items that become grid or flex items lose their float behaviour
▸ vertical-align has no effect on a grid item
▸ Items set to display: inline-block or display: block become grid items
▸ Your overrides mostly will be concerned with changing widths, margins and
padding.
▸ If grid tracks or flex-basis seem to be using a size you didn’t expect, check
your item widths!
https://rachelandrew.co.uk/css/cheatsheets/grid-fallbacks
Magazine style layouts three ways

- https://cssgrid.me/feature-figure
Media Object
▸ contains an image plus content ✓
▸ is flexible ✓
▸ elements should stack on mobile ✓
▸ box should clear the contents ✓
▸ image can be to the left or the right ✓
▸ can be nested ✓
.media:after {
content: "";
display: table;
clear: both;
}
.media > .media {
margin-left: 160px;
clear: both;
}
Media Object
We need to add a ‘clearfix’ to the
media object outside the Feature
Queries, and also clear nested Media
Objects.
.media .img {
float: left;
margin: 0 10px 0 0;
width: 150px;
}
.media.media-flip .img {
float: right;
margin: 0 0 0 10px;
}
.media > * {
margin: 0 0 0 160px;
}
.media.media-flip > * {
margin: 0 160px 0 0;
}
Media Object
The image is floated left, or right.
Add a right, or left margin to the
other child elements.
@supports(display: grid ) {
.media > *,
.media.media-flip > * {
margin: 0;
}
.media .img,
.media.media-flip .img {
width: auto;
margin: 0;
}
.media:after {
content: none;
}
/* the rest of my CSS for grid */
}
Media Object
The overrides are to remove margins
and widths and the now redundant
generated content for clearing.
<div class="media">
<div class="img">
<img src="/assets/img/placeholder.jpg"
alt="Placeholder">
</div>
<h2 class="title">This is my title</h2>
<div class="content">
</div>
<div class="footer">
footer here
</div>
</div>
Media Object
Moving the title below the image in
the source.
.media {
display: grid;
grid-column-gap: 20px;
grid-template-areas:
"title"
"img"
"bd"
"ft";
}
Media Object
A single column grid to arrange our
elements for narrow widths.
A variety of Media Objects - https://cssgrid.me/media-objects
What happened to
vendor prefixes?
Vendor Prefixes
▸ Vendor specific extensions to CSS
▸ Used by browsers to expose experimental features
▸ Used by developers to use those experimental features in production
Prefix Removals
▸ The only prefixed Grid is the old IE10 implementation -ms prefix
▸ shape-outside is -webkit prefixed in Safari and iOS Safari 10
▸ The -webkit prefix has been removed from shape-outside, so future Safari
shouldn’t need it
▸ Flexbox is now unprefixed in all browsers
For older browsers
▸ Check caniuse.com to see where you still need prefixes
▸ Autoprefixer uses the Can I Use database to add these automatically
▸ Autoprefixer will prefix very simple grids with the -ms version. In simple cases
this may work for you.
▸ Autoprefixer may also make a terrible mess if you have used properties not
part of the IE implementation. Be sure to test!
Creating Layout
<div class="post">
<article class="main">
<!— fancy header —>
<div class=“body">
<!— article content —>
</div>
</article>
<div class="comments">
<h3>Comments</h3>
<!— media objects —>
</div>
<aside class="extras">
<!— feature figure —>
</aside>
</div>
Article Layout
The skeleton layout mark-up
.post {
margin: 1em auto;
padding: 0 20px;
max-width: 960px;
}
.post .body {
margin: 0 0 2em 0;
}
Article Layout
Basic CSS for a single column article
layout.
@supports(display: grid) {
@media(min-width: 900px) {
.post > .main { grid-area: article;}
.post > .comments { grid-area: side;}
.post > .extras { grid-area: secondary;}
.post {
display: grid;
grid-template-columns: 3fr 2fr;
grid-template-areas:
"article side"
"secondary side”;
grid-column-gap: 80px;
max-width: 1600px;
}
}
}
Article Layout
If we have grid and a wide screen, I’m
going to take advantage of that.
Your component is
already a reduced test
case.
This is not twice
the work
This is not about
fallback support
This is 

evergreen design
Design that enhances
itself as the platform it
lives on improves.
@rachelandrew
Thank you #aeasea

More Related Content

What's hot

CSSConf.asia - Laying out the future
CSSConf.asia - Laying out the futureCSSConf.asia - Laying out the future
CSSConf.asia - Laying out the futureRachel Andrew
 
CSS Grid Layout - All Things Open
CSS Grid Layout - All Things OpenCSS Grid Layout - All Things Open
CSS Grid Layout - All Things OpenRachel Andrew
 
Laying out the future
Laying out the futureLaying out the future
Laying out the futureRachel Andrew
 
Making the most of New CSS Layout
Making the most of New CSS LayoutMaking the most of New CSS Layout
Making the most of New CSS LayoutRachel Andrew
 
Introducing CSS Grid Layout
Introducing CSS Grid LayoutIntroducing CSS Grid Layout
Introducing CSS Grid LayoutRachel Andrew
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout Rachel Andrew
 
The New CSS Layout - dotCSS
The New CSS Layout - dotCSSThe New CSS Layout - dotCSS
The New CSS Layout - dotCSSRachel Andrew
 
CSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NECSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NERachel Andrew
 
Future Layout & Performance
Future Layout & PerformanceFuture Layout & Performance
Future Layout & PerformanceRachel Andrew
 
Evergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsersEvergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsersRachel Andrew
 
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...Igalia
 
Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Rachel Andrew
 
Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Rachel Andrew
 
The Right Layout Tool for the Job
The Right Layout Tool for the JobThe Right Layout Tool for the Job
The Right Layout Tool for the JobRachel Andrew
 
Confoo: The New CSS Layout
Confoo: The New CSS LayoutConfoo: The New CSS Layout
Confoo: The New CSS LayoutRachel Andrew
 
GOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatRachel Andrew
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid LayoutRachel Andrew
 

What's hot (20)

CSSConf.asia - Laying out the future
CSSConf.asia - Laying out the futureCSSConf.asia - Laying out the future
CSSConf.asia - Laying out the future
 
CSS Grid Layout
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
 
CSS Grid Layout - All Things Open
CSS Grid Layout - All Things OpenCSS Grid Layout - All Things Open
CSS Grid Layout - All Things Open
 
Laying out the future
Laying out the futureLaying out the future
Laying out the future
 
CSS Grid for html5j
CSS Grid for html5jCSS Grid for html5j
CSS Grid for html5j
 
Making the most of New CSS Layout
Making the most of New CSS LayoutMaking the most of New CSS Layout
Making the most of New CSS Layout
 
Introducing CSS Grid Layout
Introducing CSS Grid LayoutIntroducing CSS Grid Layout
Introducing CSS Grid Layout
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
 
The New CSS Layout - dotCSS
The New CSS Layout - dotCSSThe New CSS Layout - dotCSS
The New CSS Layout - dotCSS
 
CSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NECSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NE
 
Future Layout & Performance
Future Layout & PerformanceFuture Layout & Performance
Future Layout & Performance
 
Evergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsersEvergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsers
 
Next-level CSS
Next-level CSSNext-level CSS
Next-level CSS
 
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
CSS Grid Layout. Implementation status and roadmap (Webkit Contributors Meeti...
 
Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17
 
Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!
 
The Right Layout Tool for the Job
The Right Layout Tool for the JobThe Right Layout Tool for the Job
The Right Layout Tool for the Job
 
Confoo: The New CSS Layout
Confoo: The New CSS LayoutConfoo: The New CSS Layout
Confoo: The New CSS Layout
 
GOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for that
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
 

Similar to An Event Apart Seattle - New CSS Layout Meets the Real World

New CSS Layout Meets the Real World
New CSS Layout Meets the Real WorldNew CSS Layout Meets the Real World
New CSS Layout Meets the Real WorldRachel Andrew
 
Start Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSRachel Andrew
 
DevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout todayDevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout todayRachel Andrew
 
The Creative New World of CSS
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSSRachel Andrew
 
Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Rachel Andrew
 
Solving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsSolving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsFITC
 
View Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & FriendsView Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & FriendsRachel Andrew
 
Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Rachel Andrew
 
404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & FriendsRachel Andrew
 
Solving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSRachel Andrew
 
ViA Bootstrap 4
ViA Bootstrap 4ViA Bootstrap 4
ViA Bootstrap 4imdurgesh
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4Gheyath M. Othman
 
Twitter bootstrap training_session_ppt
Twitter bootstrap training_session_pptTwitter bootstrap training_session_ppt
Twitter bootstrap training_session_pptRadheshyam Kori
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAPJeanie Arnoco
 

Similar to An Event Apart Seattle - New CSS Layout Meets the Real World (20)

New CSS Layout Meets the Real World
New CSS Layout Meets the Real WorldNew CSS Layout Meets the Real World
New CSS Layout Meets the Real World
 
Start Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJS
 
DevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout todayDevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout today
 
The Creative New World of CSS
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSS
 
Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout
 
World of CSS Grid
World of CSS GridWorld of CSS Grid
World of CSS Grid
 
Solving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and FriendsSolving Layout Problems With CSS Grid and Friends
Solving Layout Problems With CSS Grid and Friends
 
View Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & FriendsView Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & Friends
 
Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17
 
404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends
 
Solving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJS
 
Css 3 session1
Css 3 session1Css 3 session1
Css 3 session1
 
Css3
Css3Css3
Css3
 
Jina Bolton
Jina BoltonJina Bolton
Jina Bolton
 
ViA Bootstrap 4
ViA Bootstrap 4ViA Bootstrap 4
ViA Bootstrap 4
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4
 
Twitter bootstrap training_session_ppt
Twitter bootstrap training_session_pptTwitter bootstrap training_session_ppt
Twitter bootstrap training_session_ppt
 
CSS Grid Layout
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAP
 
BOTSTRAP.ppt
BOTSTRAP.pptBOTSTRAP.ppt
BOTSTRAP.ppt
 

More from Rachel Andrew

All Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid LayoutAll Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid LayoutRachel Andrew
 
SmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid LayoutSmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid LayoutRachel Andrew
 
Unlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid LayoutUnlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid LayoutRachel Andrew
 
Into the Weeds of CSS Layout
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS LayoutRachel Andrew
 
Laying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf FreiburgLaying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf FreiburgRachel Andrew
 
Web Summer Camp Keynote
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp KeynoteRachel Andrew
 
An Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real WorldAn Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real WorldRachel Andrew
 
Perch, Patterns and Old Browsers
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old BrowsersRachel Andrew
 
Where does CSS come from?
Where does CSS come from?Where does CSS come from?
Where does CSS come from?Rachel Andrew
 

More from Rachel Andrew (10)

All Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid LayoutAll Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid Layout
 
SmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid LayoutSmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid Layout
 
Unlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid LayoutUnlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid Layout
 
Into the Weeds of CSS Layout
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS Layout
 
Graduating to Grid
Graduating to GridGraduating to Grid
Graduating to Grid
 
Laying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf FreiburgLaying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf Freiburg
 
Web Summer Camp Keynote
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp Keynote
 
An Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real WorldAn Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real World
 
Perch, Patterns and Old Browsers
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old Browsers
 
Where does CSS come from?
Where does CSS come from?Where does CSS come from?
Where does CSS come from?
 

Recently uploaded

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Recently uploaded (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

An Event Apart Seattle - New CSS Layout Meets the Real World

  • 1. New CSS Layout Meets the Real World Rachel Andrew @ An Event Apart Seattle
  • 2. “The state of the use of Cascading Style Sheet on the web is really beginning to get boring. Why haven't designers begun exploiting its benefits yet?”
  • 3. I can remember a time not too long ago when individuals were running amok exploiting the simplest of html tags and creating works of beauty. But now, after browser vendors have stepped it up and given us much of the control we've been asking for, I can't seem to find web designers that are exploiting these new found powers.
  • 4. I can remember a time not too long ago when individuals were running amok exploiting the simplest of html tags and creating works of beauty. But now, after browser vendors have stepped it up and given us much of the control we've been asking for, I can't seem to find web designers that are exploiting these new found powers. Chris Casciano
  • 5. 2nd October 2001 Chris Casciano http://www.chunkysoup.net/opinion/boringcss/
  • 10. March 2017 March 2017 March 2017 March 2017 March 2017 Soooooon!
  • 15. Featuring ▸ Flexbox ▸ CSS Grid Layout ▸ Box Alignment ▸ CSS Shapes ▸ CSS Feature Queries
  • 17.
  • 19. Media Object ▸ contains an image plus content ▸ is flexible ▸ elements should stack on mobile ▸ box should clear the contents ▸ image can be to the left or the right ▸ can be nested
  • 20. Avoid pre-empting the need for markup as styling hooks.
  • 21. <div class="media"> <h2 class="title">This is my title</ h2> <div class="img"> <img src="/assets/img/ placeholder.jpg" alt="Placeholder"> </div> <div class="content"> </div> <div class="footer"> footer here </div> </div> Media Object A parent with a class of ‘media’ Four child elements: - title - img - content - footer
  • 22.
  • 23.
  • 24.
  • 25. @media (min-width: 600px) { .media { display: grid; } } Media Object To create a grid use a new value of the display property: display: grid
  • 26. @media (min-width: 600px) { .media { display: grid; grid-column-gap: 20px; } } Media Object Create gutters between grid cells: - grid-column-gap - grid-row-gap - grid-gap
  • 27. @media (min-width: 600px) { .media { display: grid; grid-column-gap: 20px; grid-template-columns: 1fr 3fr; } } Media Object The grid-template-columns property creates column tracks on the grid. The new fr unit represents a fraction of the available space.
  • 28.
  • 29.
  • 30. .media > .title { grid-area: title; } .media > .img { grid-area: img; } .media > .content { grid-area: bd; } .media > .footer { grid-area: ft; } Media Object Define areas with grid-area
  • 31. @media (min-width: 600px) { .media { display: grid; grid-column-gap: 20px; grid-template-columns: 1fr 3fr; grid-template-areas: "img title" "img bd" "img ft"; } } Media Object Describing layout with the 
 grid-template-areas property
  • 32.
  • 34.
  • 35. auto
  • 36. <div class="flex-example"> <div class="one">Box one</div> <div class="two">Box two</div> <div class="three"> <div class="inner">Box three</div> </div> </div> auto as flex-basis Box one, two and three are nested inside flex-example. There is another element nested inside box three.
  • 37. .flex-example { display: flex; } .flex-example > div { flex: 1 1 auto; } auto as flex-basis The parent becomes a flex container, and all direct children are set to grow and shrink from a flex-basis of auto.
  • 38. no box has a width, and flex-basis is auto and so resolved from the content
  • 39. .flex-example { display: flex; } .flex-example > div { flex: 1 1 auto; } .two { width: 350px; } .three .inner { width: 200px; } auto as flex-basis Use auto and the flex-basis will be taken from any width set on the item. If there is no width, flex-basis will be taken from the content width.
  • 40. width 350px nested item width 200pxno width https://cssgrid.me/flex-auto
  • 41. @media (min-width: 600px) { .media { display: grid; grid-column-gap: 20px; grid-template-columns: 1fr 3fr; grid-template-rows: auto 1fr; grid-template-areas: "img title" "img bd" "img ft"; } } Media Object The grid-template-rows property defines the rows on the grid. If we don’t define rows grid will create them as part of the implicit grid.
  • 42. @media (min-width: 600px) { .media { display: grid; grid-column-gap: 20px; grid-template-columns: 150px 1fr; grid-template-rows: auto 1fr; grid-template-areas: "img title" "img bd" "img ft"; } } Media Object Mix absolute lengths with fr units to have flexible containers that have some fixed width tracks.
  • 43. Media Object ▸ contains an image plus content ✓ ▸ is flexible ✓ ▸ elements should stack on mobile ✓ ▸ box should clear the contents ✓ ▸ image can be to the left or the right ▸ can be nested
  • 44. @media (min-width: 600px) { .media { display: grid; grid-column-gap: 20px; grid-template-columns: 150px 1fr; grid-template-rows: auto 1fr; grid-template-areas: "img title" "img bd" "img ft"; } .media.media-flip { grid-template-columns: 1fr 150px; grid-template-areas: "title img" "bd img" "ft img"; } } Media Object Flipping the display by creating new rules for the ‘media-flip’ class.
  • 45.
  • 46. Media Object ▸ contains an image plus content ✓ ▸ is flexible ✓ ▸ elements should stack on mobile ✓ ▸ box should clear the contents ✓ ▸ image can be to the left or the right ✓ ▸ can be nested
  • 47.
  • 48. .media > .media { grid-column: 2 / -1 ; } Media Object If an item with a class of media is the direct child of an item with a class of media, start on column line 2. Line -1 is the final line of the grid.
  • 49.
  • 50.
  • 51. Media Object ▸ contains an image plus content ✓ ▸ is flexible ✓ ▸ elements should stack on mobile ✓ ▸ box should clear the contents ✓ ▸ image can be to the left or the right ✓ ▸ can be nested ✓
  • 53.
  • 54. <figure class=“feature-fig"> <figcaption>caption</figcaption> <img src="placeholder1.jpg" alt="placeholder 1"> <img src="placeholder1.jpg" alt="placeholder 2"> <img src="placeholder1.jpg" alt="placeholder 3"> </figure> Magazine Style Layout The block is a figure with three images and a caption.
  • 55.
  • 56. <div class="half-border"> <p class="inner">Content here</p> </div> Half-border Box Creating the half-border box as a standalone pattern.
  • 57. .half-border { display: grid; border-top: 2px solid #000; grid-template-rows: minmax(30px, 1fr) 2fr; } Half-border Box I’m using grid layout to create a single column, 2 row grid.
  • 59. 1fr 1fr 1fr 1fr 1frminmax(400px, 1fr) 700px container
  • 61. .half-border { display: grid; border-top: 2px solid #000; grid-template-rows: minmax(30px, 1fr) 2fr; align-self: start; } Half-border Box The first row of the grid is a minimum of 30px tall, a maximum of 1fr.
  • 62. .half-border::before { content: ""; border-left: 2px solid #000; grid-row: 1; grid-column: 1; } Half-border Box A pseudo-element created with generated content will also become a grid item.
  • 63.
  • 64. .half-border .inner { grid-row: 1 / 3; grid-column: 1; margin: 10px; } Half-border Box The inner starts at row line 1 and ends at row line 3, spanning 2 row tracks.
  • 65.
  • 66. <figure class="feature-fig"> <figcaption class="half-border"> <p class="inner">caption</p> </figcaption> <img src="placeholder1.jpg" alt="placeholder 1"> <img src="placeholder1.jpg" alt="placeholder 2"> <img src="placeholder1.jpg" alt="placeholder 3"> </figure> Magazine Style Layout Adding the half-border classes.
  • 67.
  • 68. @media (min-width: 600px) { .feature-fig { display: grid; grid-template-columns: 2fr 2fr 1fr; } .feature-fig img { object-fit: cover; } } Magazine Style Layout Defining a grid with 3 column tracks.
  • 69.
  • 70. @media (min-width: 600px) { .feature-fig { display: grid; grid-template-columns: 2fr 2fr 1fr; grid-template-rows: minmax(200px, auto) minmax(100px, auto) auto minmax(100px,auto); } .feature-fig img { object-fit: cover; } } Magazine Style Layout Creating row tracks. The minmax() notation means that we can set a minimum size for the tracks.
  • 71. .feature-fig figcaption { grid-column: 1; grid-row: 3; margin-top: 10px; } Magazine Style Layout Position the figcaption after grid column line 1, and grid row line 3
  • 72.
  • 73. .feature-fig .main { grid-row: 1 / 3; grid-column: 1 / 3; z-index: 2; } .feature-fig .insert { grid-row: 2 / 5; grid-column: 2 / 4; border-top: 10px solid #fff; border-left: 10px solid #fff; z-index: 3; } .feature-fig .small { grid-row: 4 / 6; grid-column: 1 ; } Magazine Style Layout The items are positioned using line- based positioning. Grid items respect z-index so we can layer items that end up in the same cells.
  • 74.
  • 75. .photo-circle { border-radius: 50%; } Magazine Style Layout Setting border-radius to 50% gives us a circle.
  • 76.
  • 78.
  • 79. <header class="run-header"> <h1> 4.5 Miles in Berlin, Germany</h1> <div class="intro"> <p> </p> </div> </header> Fancy Header The mark-up for the article header
  • 80. <header class="run-header"> <h1><span class="distance-wrap"> <span class="distance">4.5</span> <span class="miles">Miles</span></ span> <span class="location">in Berlin, Germany</span></h1> <div class="intro"> <p> </p> </div> </header> Fancy Header We need to add some mark-up to identify the parts of the h1 text we want to style.
  • 81.
  • 82. .run-header .distance-wrap { border-radius: 50%; width: 5em; height: 5em; padding: 0; background: linear- gradient(rgba(0,0,0,0), rgba(0,0,0,0.8)),url(/assets/img/flag- germany.jpg) center center; background-size: cover; margin: 0 auto 1em auto; z-index: 2; } Fancy Header I use border-radius set to 50% to make the distance part of the header a circle.
  • 83.
  • 84. .run-header .distance-wrap { display: block; border-radius: 50%; width: 5em; height: 5em; padding: 0; background: linear- gradient(rgba(0,0,0,0), rgba(0,0,0,0.8)),url(/assets/img/flag- germany.jpg) center center; background-size: cover; margin: 0 auto 1em auto; z-index: 2; } Fancy Header Setting display to block will mean the span becomes block level.
  • 85.
  • 86. .run-header .distance-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 50%; width: 5em; height: 5em; padding: 0; background: linear- gradient(rgba(0,0,0,0), rgba(0,0,0,0.8)),url(/assets/img/flag- germany.jpg) center center; background-size: cover; margin: 0 auto 1em auto; z-index: 2; } Fancy Header I use border-radius set to 50% to make the distance part of the header a circle.
  • 87.
  • 88. @media (min-width: 600px) { .run-header .distance-wrap { float: left; margin: 0 10px 10px 0; } .run-header h1 { text-align: left; width: 100%; } .run-header .location { display: inline-block; padding-left: 1em; margin-left: -1em; } .intro { padding: 0; } } Fancy Header Floating the distance-wrap class left means the location comes up alongside it.
  • 89.
  • 90. @media (min-width: 600px) { .run-header .distance-wrap { float: left; margin: 0 10px 10px 0; } .run-header h1 { text-align: left; width: 100%; } .run-header .location { display: inline-block; padding-left: 1em; margin-left: -1em; } .intro { padding: 0; } } Fancy Header We can use the shape-outside property with a value of margin-box to create the curved text.
  • 91. @media (min-width: 600px) { .run-header .distance-wrap { float: left; shape-outside: margin-box; margin: 0 10px 10px 0; } .run-header h1 { text-align: left; width: 100%; } .run-header .location { display: inline-block; padding-left: 1em; margin-left: -1em; } .intro { padding: 0; } } Fancy Header We can use the shape-outside property with a value of margin-box to create the curved text.
  • 92.
  • 93.
  • 94.
  • 95. Design for the extreme edges of the experience.
  • 99.
  • 102.
  • 103. @supports (shape-outside: margin-box) { } Fancy Header A Feature Query looks very similar to Media Queries. Here we test for a property and value pair.
  • 104. Using Feature Queries ▸ Write CSS for browsers without support ▸ Override those properties inside the feature queries ▸ See https://hacks.mozilla.org/2016/08/using-feature-queries-in-css/ ▸ A component based approach helps to keep this all in check!
  • 105. .intro { padding: 0; margin-left: 9em; } @supports (shape-outside: margin-box) { .run-header .distance-wrap { shape-outside: margin-box; margin: 0 10px 10px 0; } .intro { margin-left: 0; } } Fancy Header Outside of the feature query I add a left margin to the intro. Inside the feature query we add the shape-outside property and also remove that margin.
  • 106. Fancy Header three ways - https://cssgrid.me/fancy-headers
  • 107.
  • 108.
  • 109. @supports(display: grid) { } Half-border Box Using a Feature Query to check for Grid Layout support
  • 110. .half-border { display: inline-block; border: 2px solid #000; padding: 10px; } @supports(display: grid) { .half-border { border: 0; padding: 0; /* the rest of my CSS for grid */ } } Half-border Box Outside the Feature Query write CSS to style the box. Override that for Grid supporting browsers inside the query.
  • 112. @media (min-width: 600px) { .half-border { width: 45%; display: inline-block; vertical-align: top; } .feature-fig img { object-fit: cover; display: inline-block; width: 45%; } .feature-fig .small { vertical-align: bottom; margin: 0 0 20px 5%; } .photo-circle { border-radius: 50%; } @supports(display: grid) { .feature-fig img, .half-border { width: auto; } .feature-fig .small { margin: 0; } /* the rest of my CSS for grid */ } } Magazine Style Layout Outside the Feature Query add CSS for non-grid browsers. Inside write CSS to override plus the rules for grid layout.
  • 113.
  • 114. @media (min-width: 600px) { .half-border { width: 45%; display: inline-block; vertical-align: top; } .feature-fig img { object-fit: cover; display: inline-block; width: 45%; } .feature-fig .small { vertical-align: bottom; margin: 0 0 20px 5%; } .photo-circle { border-radius: 50%; } @supports(display: grid) { .feature-fig img, .half-border { width: auto; } .feature-fig .small { margin: 0; } /* the rest of my CSS for grid */ } } Magazine Style Layout Outside the Feature Query add CSS for non-grid browsers. Inside write CSS to override plus the rules for grid layout.
  • 115. If using display: grid or display: flex ▸ Floated items that become grid or flex items lose their float behaviour ▸ vertical-align has no effect on a grid item ▸ Items set to display: inline-block or display: block become grid items ▸ Your overrides mostly will be concerned with changing widths, margins and padding. ▸ If grid tracks or flex-basis seem to be using a size you didn’t expect, check your item widths!
  • 117. Magazine style layouts three ways
 - https://cssgrid.me/feature-figure
  • 118.
  • 119. Media Object ▸ contains an image plus content ✓ ▸ is flexible ✓ ▸ elements should stack on mobile ✓ ▸ box should clear the contents ✓ ▸ image can be to the left or the right ✓ ▸ can be nested ✓
  • 120. .media:after { content: ""; display: table; clear: both; } .media > .media { margin-left: 160px; clear: both; } Media Object We need to add a ‘clearfix’ to the media object outside the Feature Queries, and also clear nested Media Objects.
  • 121. .media .img { float: left; margin: 0 10px 0 0; width: 150px; } .media.media-flip .img { float: right; margin: 0 0 0 10px; } .media > * { margin: 0 0 0 160px; } .media.media-flip > * { margin: 0 160px 0 0; } Media Object The image is floated left, or right. Add a right, or left margin to the other child elements.
  • 122. @supports(display: grid ) { .media > *, .media.media-flip > * { margin: 0; } .media .img, .media.media-flip .img { width: auto; margin: 0; } .media:after { content: none; } /* the rest of my CSS for grid */ } Media Object The overrides are to remove margins and widths and the now redundant generated content for clearing.
  • 123.
  • 124.
  • 125. <div class="media"> <div class="img"> <img src="/assets/img/placeholder.jpg" alt="Placeholder"> </div> <h2 class="title">This is my title</h2> <div class="content"> </div> <div class="footer"> footer here </div> </div> Media Object Moving the title below the image in the source.
  • 126.
  • 127. .media { display: grid; grid-column-gap: 20px; grid-template-areas: "title" "img" "bd" "ft"; } Media Object A single column grid to arrange our elements for narrow widths.
  • 128.
  • 129. A variety of Media Objects - https://cssgrid.me/media-objects
  • 131. Vendor Prefixes ▸ Vendor specific extensions to CSS ▸ Used by browsers to expose experimental features ▸ Used by developers to use those experimental features in production
  • 132. Prefix Removals ▸ The only prefixed Grid is the old IE10 implementation -ms prefix ▸ shape-outside is -webkit prefixed in Safari and iOS Safari 10 ▸ The -webkit prefix has been removed from shape-outside, so future Safari shouldn’t need it ▸ Flexbox is now unprefixed in all browsers
  • 133. For older browsers ▸ Check caniuse.com to see where you still need prefixes ▸ Autoprefixer uses the Can I Use database to add these automatically ▸ Autoprefixer will prefix very simple grids with the -ms version. In simple cases this may work for you. ▸ Autoprefixer may also make a terrible mess if you have used properties not part of the IE implementation. Be sure to test!
  • 135.
  • 136. <div class="post"> <article class="main"> <!— fancy header —> <div class=“body"> <!— article content —> </div> </article> <div class="comments"> <h3>Comments</h3> <!— media objects —> </div> <aside class="extras"> <!— feature figure —> </aside> </div> Article Layout The skeleton layout mark-up
  • 137. .post { margin: 1em auto; padding: 0 20px; max-width: 960px; } .post .body { margin: 0 0 2em 0; } Article Layout Basic CSS for a single column article layout.
  • 138.
  • 139. @supports(display: grid) { @media(min-width: 900px) { .post > .main { grid-area: article;} .post > .comments { grid-area: side;} .post > .extras { grid-area: secondary;} .post { display: grid; grid-template-columns: 3fr 2fr; grid-template-areas: "article side" "secondary side”; grid-column-gap: 80px; max-width: 1600px; } } } Article Layout If we have grid and a wide screen, I’m going to take advantage of that.
  • 140.
  • 141. Your component is already a reduced test case.
  • 142. This is not twice the work
  • 143. This is not about fallback support
  • 145. Design that enhances itself as the platform it lives on improves.