The New CSS Layout - Dutch PHP Conference

Rachel Andrew
Rachel AndrewWriter, speaker, co-founder of Perch CMS. Google Developer Expert for Web Technologies at A List Apart
The New CSS Layout
Rachel Andrew
Dutch PHP Conference, 2015
Rachel Andrew
http://rachelandrew.co.uk
@rachelandrew
http://grabaperch.com
The trouble with CSS layout
• Floats and clearfix hacks
• Absolute positioning means elements are taken
out of document flow and risk overlaps
• Redundant markup and positioning oddities with
display: table
• White space issues with inline-block
The cost of taming layout methods
• Developer hours spent learning non-obvious
concepts.
• Compromises in terms of document semantics in
order to achieve responsive layouts.
• Needing to lean on frameworks to help with
complex math.
• Adding markup to create grids
• Using preprocessors to abstract layout hacks
Multi-column
Layout
http://www.w3.org/TR/css3-multicol/
http://dev.w3.org/csswg/css-multicol-1/
http://www.flickr.com/photos/62693815@N03/6277209256/
http://caniuse.com/#search=multicol
In my HTML I have an
article with a class of
‘main’.
<article class="main">
<h1>Blanchard Crosses the Sea in a
Balloon</h1>
<p> ... </p>
</article>
The New CSS Layout - Dutch PHP Conference
Use the property column-
width to declare a width
for our columns.
The browser will create
as many columns as
possible using that as the
ideal width.
.main {
column-width: 220px;
}
The New CSS Layout - Dutch PHP Conference
CSS Multiple column layout
[The column-width value] describes the optimal
column width. The actual column width may be
wider (to fill the available space), or narrower
(only if the available space is smaller than the
specified column width). Specified values must
be greater than 0.
Set the property column-
count to 3 and the
browser will always
create three columns.
.main {
column-count: 3;
}
The gap between columns
is controlled by the
column-gap property.
Give this a value of 0 and
you have no gap.
.main {
column-count: 3;
column-gap: 0;
}
The New CSS Layout - Dutch PHP Conference
The browser takes the
column-gap into account
when calculating the size
of the columns.
.main {
column-count: 3;
column-gap: 20px;
}
Styling columns
• very limited in the current specification
• cannot set size of an individual column
• cannot change background colour of a column
• cannot set padding or margins on a column
Multiple column layout
future specifications may add additional
functionality. For example, columns of
different widths and different backgrounds
may be supported.
Add a rule between
columns using the
column-rule property.
This is a shorthand for:
column-rule-width
column-rule-style
column-rule-color
These properties behave
just like the border
properties.
.main {
column-count: 3;
column-gap: 20px;
column-rule: 2px dotted #ccc;
}
The New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP Conference
The property column-
span can have a value of
all or none. If set to all the
element will span all
columns.
.main h1,
.image {
column-span: all;
}
The New CSS Layout - Dutch PHP Conference
Use multiple column layout to tidy
up the display of small UI elements.
The New CSS Layout - Dutch PHP Conference
Resources
Dev.Opera: https://dev.opera.com/articles/css3-multi-column-layout/
MDN: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_multi-
column_layouts
CSS Tricks: https://css-tricks.com/guide-responsive-friendly-css-columns/
Multi-column generator: http://aaronlumsden.com/multicol/
Flexible Box Layout
http://www.w3.org/TR/css-flexbox-1/
http://dev.w3.org/csswg/css-flexbox/
https://www.flickr.com/photos/zervas/2810241612
http://caniuse.com/#feat=flexbox
Navigation marked up as
an unordered list in my
HTML.
<nav>
<ul class="nav">
<li><a href="">Introduction</a></li>
<li><a href="">Ancient Times</a></li>
<li><a href="">Balloon Theory</a></li>
<li><a href="">First Public Trial</a></
li>
<li><a href="">Experiments</a></li>
</ul>
</nav>
The New CSS Layout - Dutch PHP Conference
flex is a new value of the
display property. This
causes the element to use
flexbox.
justify-content lets us set
how the content is
justified. nav ul{
display: flex;
justify-content: space-between;
}
The New CSS Layout - Dutch PHP Conference
To have equal space all
around the item give
justify-content a value of
space-around.
nav ul{
display: flex;
justify-content: space-around;
}
The New CSS Layout - Dutch PHP Conference
Default flexbox behaviour
• Items displayed as a row
• Items displayed in natural (DOM) order
• align-items set to stretch
• flex-wrap set to nowrap
The flex-direction
property.
- row
- row-reverse
- column
- column-reverse
nav ul{
display: flex;
justify-content: space-around;
flex-direction: row;
}
The flex-direction
property.
- row
- row-reverse
- column
- column-reverse
nav ul{
display: flex;
justify-content: space-around;
flex-direction: row-reverse;
}
The New CSS Layout - Dutch PHP Conference
The flex-direction
property.
- row
- row-reverse
- column
- column-reverse
nav ul{
display: flex;
justify-content: space-around;
flex-direction: column;
}
The New CSS Layout - Dutch PHP Conference
The align-items property:
- flex-start
- flex-end
- center
- baseline
- stretch
nav ul{
display: flex;
justify-content: space-between;
align-items: flex-end;
}
The New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP Conference
Our boxes are displayed
using flexbox. If there is
not space for all 3 they
will wrap as the flex-wrap
property is set to wrap.
.boxes {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.box {
border: 1px solid #444;
padding: 10px;
margin: 10px;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 200px;
min-width: 1px;
}
The flex property is a
shorthand for the three
properties. Initial values
as follows:
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
.boxes {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.box {
border: 1px solid #444;
padding: 10px;
margin: 10px;
flex: 1 1 200px;
min-width: 1px;
}
Giving the box with a
class of .box2 a flex-grow
value of 2. The other
boxes have flex-grow set
to 1.
.box2 {
flex-grow: 2;
}
The New CSS Layout - Dutch PHP Conference
Use the order property to
change the order of flex
items.
.box1 {
order: 3;
}
.box2 {
flex-grow: 2;
order: 1;
}
.box3 {
order: 2;
}
The New CSS Layout - Dutch PHP Conference
Resources
Solved by Flexbox: http://philipwalton.github.io/solved-by-flexbox/
CSS Tricks: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Flexbox Cheat Sheet: http://www.sketchingwithcss.com/samplechapter/
cheatsheet.html
Flexbox in 5: http://flexboxin5.com/
Useful information on supporting older browsers:
http://www.planningforaliens.com/blog/2014/03/11/real-world-flexbox/
http://zomigi.com/downloads/Leveling-Up-With-Flexbox_SmashingConf_140319.pdf
CSS Shapes
http://www.w3.org/TR/css-shapes/
http://dev.w3.org/csswg/css-shapes/
http://dev.w3.org/csswg/css-shapes-2/
https://www.flickr.com/photos/randar/8063840431
http://webplatform.adobe.com/shapes/
http://caniuse.com/#search=shapes
The New CSS Layout - Dutch PHP Conference
We have floated our
image left.
.shape {
float: left;
width: 150px;
height: 150px;
margin: 20px;
}
Add the property shape-
outside with a value of
circle(50%).
.shape {
float: left;
width: 150px;
height: 150px;
margin: 20px;
shape-outside: circle(50%);
}
The New CSS Layout - Dutch PHP Conference
http://betravis.github.io/shape-tools/
The New CSS Layout - Dutch PHP Conference
Basic Shapes
• inset()
• circle()
• ellipse()
• polygon()
Using the polygon value
for shape-inside.
The polygon requires at
least 3 sets of x, y
coordinates.
.shape {
float: left;
width: 200px;
height: 200px;
margin-top: 10px;
}
.shape-polygon {
shape-outside: polygon(0 20px, 160px
40px, 180px 70px, 180px 120px, 120px
200px, 60px 210px, 0 220px);
}
The New CSS Layout - Dutch PHP Conference
Shapes from the Alpha Channel
http://enable-cors.org/
My HTML contains an
image along with some
text.
<div class="s-box">
<img src="noun_109069.png" alt=""
width="200" class="shape shape-image”>
<p> ... </p>
</div>
To use an alpha channel
pass in a URL for your
image and a threshold for
the transparency.
.shape-image {
shape-outside: url('noun_109069.png');
shape-image-threshold: 0.5;
}
The New CSS Layout - Dutch PHP Conference
Use an image in
generated content to
shape your text.
.content:before {
content: "";
float: left;
width: 200px;
height: 200px;
shape-outside: url('alpha.png');
shape-image-threshold: 0.5;
}
The New CSS Layout - Dutch PHP Conference
What’s next for Shapes?
• shape-inside - text flowing inside a shape
• shapes defined on elements that are not floated
• shape-padding property
• Level 2 specification http://dev.w3.org/csswg/
css-shapes-2
Resources
How to Get Started with CSS Shapes: http://www.webdesignerdepot.com/2015/03/
how-to-get-started-with-css-shapes/
A List Apart: http://alistapart.com/article/css-shapes-101
HTML5 Rocks: http://www.html5rocks.com/en/tutorials/shapes/getting-started/
How to prepare images using Photoshop: http://blogs.adobe.com/webplatform/
2014/03/11/add-shape-and-depth-to-your-layout-with-photoshop-and-css-shapes/
Adobe: http://webplatform.adobe.com/shapes/
CSS Grid Layout
http://www.w3.org/TR/css-grid-1/
http://dev.w3.org/csswg/css-grid/
http://www.flickr.com/photos/adactio/1799953270
http://caniuse.com/#feat=css-grid
Browser Support
All my examples work in Chrome unprefixed - you need to enable
the Experimental Web Platform Features flag.
You can also use Webkit nightlies, with the -webkit prefix.
The work in Blink and Webkit is being done by Igalia, sponsored by
Bloomberg.
IE10 and up has support for the old syntax, with an -ms prefix.
Mozilla are currently implementing Grid in Firefox.
There is a Polyfill under active development: https://github.com/
FremyCompany/css-grid-polyfill/
Our HTML consists of a
div with a class of
wrapper and six child
elements.
<div class="wrapper">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
<div class="d">D</div>
<div class="e">E</div>
<div class="f">F</div>
</div>
To create a grid we use a
new value of the display
property.
display: grid
.wrapper {
display: grid;
}
We describe the grid using
the new properties:
grid-template-columns
grid-template-rows
.wrapper {
display: grid;
grid-template-columns:
100px 10px 100px 10px 100px;
grid-template-rows:
auto 10px auto;
}
We position items using the
new properties:
grid-column-start

grid-column-end

grid-row-start

grid-row-end
.a {
grid-column-start: 1;
grid-column-end: 2;
grid-row-start: 1;
grid-row-end: 2;
}
To position an item bottom
centre, I start at column
line 3, this is the line after
the gutter track.
.b {
grid-column-start: 3;
grid-column-end: 4;
grid-row-start: 3;
grid-row-end: 4;
}
To span more tracks we
just change the end row or
column line.
.b {
grid-column-start: 3;
grid-column-end: 6;
grid-row-start: 3;
grid-row-end: 4;
}
The longhand for line-
based placement means
up to 4 properties to
position each element. .a {
grid-column-start: 1;
grid-column-end: 2;
grid-row-start: 1;
grid-row-end: 2;
}
.b {
grid-column-start: 3;
grid-column-end: 4;
grid-row-start: 3;
grid-row-end: 4;
}
Declare start and end
values with grid-column
and grid-row.
Values are separated by a
/ symbol.
.a {
grid-column: 1 / 2;
grid-row: 1 / 2;
}
.b {
grid-column: 3 / 6;
grid-row: 3 / 4;
}
Declare all 4 values using
the grid-area property.
.a {
grid-area: 1 / 1 / 2 / 2;
}
.b {
grid-area: 3 / 3 / 4 / 6;
}
Grid Terminology
Grid Lines
Lines can be horizontal or vertical. They
are referred to by number and can be
named.
Highlighted is Column Line 2.
Grid Track
A Grid Track is the space between two
Grid Lines. Tracks can be horizontal or
vertical (rows or columns).
The highlighted Grid Track is between
Row Lines 2 and 3.
Grid Cell
The smallest unit on our grid, a Grid Cell
is the space between four Grid Lines. It’s
just like a table cell.
The highlighted Grid Cell is between row
lines 2 and 3 and column lines 2 and 3.
Grid Area
Any area of the Grid bound by 4 Grid
Lines. It can contain many Grid Cells.
The highlighted Grid Area is between
row lines 1 and 3, column lines 2 and 4.
All examples can be found at http://gridbyexample.com. Use Chrome. Enable “Experimental Web Platform Features” flag.
Line-based placement
The New CSS Layout - Dutch PHP Conference
The HTML around my
page content.
The various areas of my
page are child elements
of a div with a class of
wrapper.
<div class="wrapper">
<header class="mainheader"></header>
<div class="panel"></div>
<div class="content"></div>
</div>
The New CSS Layout - Dutch PHP Conference
Declaring a grid on
wrapper.
The grid has three
columns, and four rows.
.wrapper {
width: 100%;
max-width: 960px;
margin: 0 auto;
display: grid;
grid-template-columns: 30% 5% 65%;
grid-template-rows: 40px auto 20px auto;
}
The New CSS Layout - Dutch PHP Conference
Positioning our elements
using the grid-column and
grid-row shorthand.
This is all we need to do
to create our layout.
.mainheader {
grid-column: 1 / 4;
grid-row: 2 / 3;
}
.panel {
grid-column: 1 / 2;
grid-row: 4 / 5;
}
.content {
grid-column: 3 / 4;
grid-row: 4 / 5;
}
The New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP Conference
I can add a footer to this
layout.
<div class="wrapper">
<header class="mainheader"></header>
<div class="panel"></div>
<div class="content"></div>
<footer class="mainfooter"></footer>
</div>
Positioning the footer
between row lines five
and six.
.mainfooter {
grid-column: 1 / 4;
grid-row: 5 / 6;
}
The New CSS Layout - Dutch PHP Conference
Our grid only has 5 row
lines specified - yet we
placed an item between
row lines 5 and 6.
Grid creates an implicit
grid line for us.
.wrapper {
display: grid;
grid-template-columns: 30% 5% 65%;
grid-template-rows: 40px auto 20px auto;
}
.mainfooter {
grid-column: 1 / 4;
grid-row: 5 / 6;
}
Grid lines can be explicit or implicit
• Explicit grid lines are those specified using grid-
template-rows or grid-template-columns.
• Implicit lines are created when you place
something into a row or column track outside of
the explicit grid.
• Default behaviour is those tracks are auto sized.
You can specify a size with the grid-auto-
columns and grid-auto-rows properties.
Grid is “table like” however …
• Unlike a table for layout Grid does not rely on
your content being a particular order in the
source.

• Being entirely described in CSS we can move
things around the Grid at different breakpoints,
introduce or redefine a Grid for any breakpoint.
Using Grid to order the
page elements in a single
column for narrow screen
widths.
.wrapper {
display: grid;
grid-template-rows:
10px auto 10px auto 10px auto 10px auto;
}
.mainheader {
grid-row: 2 / 3;
}
.content {
grid-row: 4 / 5;
}
.panel {
grid-row: 6 / 7;
}
.mainfooter {
grid-row: 8 / 9;
}
The New CSS Layout - Dutch PHP Conference
Redefine the Grid at min-
width 550 pixels.
Position items as in the
earlier example.
@media (min-width: 550px) {
.wrapper {
grid-template-columns: 30% 5% 65%;
grid-template-rows: 40px auto 20px auto 20px auto;
}
.mainheader {
grid-column: 1 / 4;
grid-row: 2 / 3;
}
.panel {
grid-column: 1 / 2;
grid-row: 4 / 5;
}
.content {
grid-column: 3 / 4;
grid-row: 4 / 5;
}
.mainfooter {
grid-column: 1 / 4;
grid-row: 6 / 7;
}
}
Named Areas
The New CSS Layout - Dutch PHP Conference
We assign a name to the
elements on our page.
I am doing this outside of
any Media Queries.
.mainheader {
grid-area: header;
}
.content {
grid-area: content;
}
.panel {
grid-area: sidebar;
}
.mainfooter {
grid-area: footer;
}
Describe the layout on
the parent element using
the grid-template-areas
property.
A period “.” indicates that
this grid cell is empty.
.wrapper {
display: grid;
grid-template-rows:
10px auto 10px auto 10px auto 10px auto;
grid-template-areas:
"."
"header"
"."
"content"
"."
"sidebar"
"."
"footer";
}
The New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP Conference
Redefining the template
areas for the wider
layout. @media (min-width: 550px) {
.wrapper {
grid-template-columns: 30% 5% 65%;
grid-template-rows:
2em auto 1em auto 1em auto;
grid-template-areas:
". . ."
"header header header"
". . ."
"sidebar . content"
". . ."
"footer footer footer"
}
}
The New CSS Layout - Dutch PHP Conference
The New CSS Layout - Dutch PHP Conference
Resources
Grid by Example: http://gridbyexample.com
Examples from Igalia: http://igalia.github.io/css-grid-layout/
An article covering the original IE10 implementation: http://24ways.org/2012/css3-
grid-layout/
CSS Exclusions
http://www.w3.org/TR/css3-exclusions/
http://dev.w3.org/csswg/css-exclusions/
https://www.flickr.com/photos/markusspiske/15115777092
http://caniuse.com/#search=exclusions
Floated items always rise to the top.
We can wrap text around the right or
left and bottom of an item.
Exclusions enable wrapping text
around all sides of an item.
I have an article with an
image as the last child in
the source.
The image has a class of
exclusion.
<article>
<p> ... </p>
<img src="balloons3.jpg" alt="Hot air
balloons" class="exclusion" />
</article>
The article has been given
position relative to create
a positioning context.
I have then positioned the
image using absolute
positioning.
.main {
position:relative;
}
.exclusion {
position: absolute;
top: 14em;
left: 14em;
width: 320px;
}
The New CSS Layout - Dutch PHP Conference
The wrap-flow property
means that the text will
respect the positioned
element and wrap round
both sides.
I’m using the -ms prefix
given this is only
implemented in IE
browsers.
.main {
position:relative;
}
.exclusion {
position: absolute;
top: 14em;
left: 14em;
width: 320px;
-ms-wrap-flow: both;
}
The New CSS Layout - Dutch PHP Conference
CSS Regions
http://www.w3.org/TR/css-regions-1/
http://dev.w3.org/csswg/css-regions/
https://www.flickr.com/photos/striatic/3529866/
http://caniuse.com/#search=regions
http://webplatform.adobe.com/regions/
Regions were in the Blink engine but
removed in January 2014. They are
still part of Safari desktop and iOS.
https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/kTktlHPJn4Q/YrnfLxeMO7IJ
I have an article contained
inside an article element.
Below that is a set of
empty elements, each
with a class of article-
regions.
<article class="main content”>
<p> ... </p>
</article>
<div class="region1 article-regions"></div>
<div class="regionwrapper">
<div class="region2 article-regions"></div>
<div class="region3 article-regions"></div>
<div class="region4 article-regions"></div>
</div>
<div class="region5 article-regions"></div>
The New CSS Layout - Dutch PHP Conference
We flow the content of
our article into ‘article-
thread’. This is a name we
have given the content.
We then flow the content
into .article-regions - this
is the class we gave our
empty elements.
.main {
flow-into: article-thread;
}
.article-regions {
flow-from: article-thread;
}
Positioning the empty
elements.
.region1 {
height: 10em;
}
.regionwrapper {
display: flex;
flex-direction: row;
}
.region2 {
flex: 1;
padding: 10px;
height: 10em;
}
.region3 {
flex: 1;
padding: 10px;
height: 10em;
}
.region4 {
flex: 1;
padding: 10px;
height: 10em;
}
.region5 {
padding: 10px;
}
The New CSS Layout - Dutch PHP Conference
Resources
An Introduction to CSS Regions: https://dev.opera.com/articles/introduction-to-css-
regions/
Use CSS Regions to flow content through a layout: https://docs.webplatform.org/wiki/
tutorials/css-regions
Say Hello to CSS Regions Polyfill: http://corlan.org/2013/02/08/say-hello-to-css-
regions-polyfill/
Introducing CSS Regions: http://www.webdesignerdepot.com/2013/09/introducing-
css-regions/
Why explore emerging
specifications?
Thank you!
Rachel Andrew
@rachelandrew
http://rachelandrew.co.uk/presentations/new-css-layout
1 of 138

Recommended

An Event Apart SF: CSS Grid Layout by
An Event Apart SF: CSS Grid LayoutAn Event Apart SF: CSS Grid Layout
An Event Apart SF: CSS Grid LayoutRachel Andrew
1.6K views137 slides
Devoxx Belgium: CSS Grid Layout by
Devoxx Belgium: CSS Grid LayoutDevoxx Belgium: CSS Grid Layout
Devoxx Belgium: CSS Grid LayoutRachel Andrew
1.2K views137 slides
CSS Day: CSS Grid Layout by
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout Rachel Andrew
9.6K views122 slides
CSS Grid Layout for Topconf, Linz by
CSS Grid Layout for Topconf, LinzCSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, LinzRachel Andrew
185K views116 slides
Flexbox and Grid Layout by
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid LayoutRachel Andrew
7K views98 slides
But what about old browsers? by
But what about old browsers?But what about old browsers?
But what about old browsers?Rachel Andrew
851 views97 slides

More Related Content

What's hot

Introduction to CSS Grid Layout by
Introduction to CSS Grid LayoutIntroduction to CSS Grid Layout
Introduction to CSS Grid LayoutRachel Andrew
3.6K views73 slides
An Event Apart Nashville: CSS Grid Layout by
An Event Apart Nashville: CSS Grid LayoutAn Event Apart Nashville: CSS Grid Layout
An Event Apart Nashville: CSS Grid LayoutRachel Andrew
1.7K views138 slides
Fluent: Making Sense of the New CSS Layout by
Fluent: Making Sense of the New CSS LayoutFluent: Making Sense of the New CSS Layout
Fluent: Making Sense of the New CSS LayoutRachel Andrew
7.7K views82 slides
Flexbox and Grid Layout by
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid LayoutRachel Andrew
2.6K views101 slides
Future Layout & Performance by
Future Layout & PerformanceFuture Layout & Performance
Future Layout & PerformanceRachel Andrew
1.8K views87 slides
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017 by
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017Morten Rand-Hendriksen
63.6K views106 slides

What's hot(20)

Introduction to CSS Grid Layout by Rachel Andrew
Introduction to CSS Grid LayoutIntroduction to CSS Grid Layout
Introduction to CSS Grid Layout
Rachel Andrew3.6K views
An Event Apart Nashville: CSS Grid Layout by Rachel Andrew
An Event Apart Nashville: CSS Grid LayoutAn Event Apart Nashville: CSS Grid Layout
An Event Apart Nashville: CSS Grid Layout
Rachel Andrew1.7K views
Fluent: Making Sense of the New CSS Layout by Rachel Andrew
Fluent: Making Sense of the New CSS LayoutFluent: Making Sense of the New CSS Layout
Fluent: Making Sense of the New CSS Layout
Rachel Andrew7.7K views
Flexbox and Grid Layout by Rachel Andrew
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
Rachel Andrew2.6K views
Future Layout & Performance by Rachel Andrew
Future Layout & PerformanceFuture Layout & Performance
Future Layout & Performance
Rachel Andrew1.8K views
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017 by Morten Rand-Hendriksen
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
CSS Grid Layout: An Event Apart Boston 2016 by Rachel Andrew
CSS Grid Layout: An Event Apart Boston 2016CSS Grid Layout: An Event Apart Boston 2016
CSS Grid Layout: An Event Apart Boston 2016
Rachel Andrew2.9K views
Building calloutswithoutwsdl2apex by Ming Yuan
Building calloutswithoutwsdl2apexBuilding calloutswithoutwsdl2apex
Building calloutswithoutwsdl2apex
Ming Yuan861 views
ConFoo 2016: Making Sense of CSS Layout by Rachel Andrew
ConFoo 2016: Making Sense of CSS LayoutConFoo 2016: Making Sense of CSS Layout
ConFoo 2016: Making Sense of CSS Layout
Rachel Andrew1.1K views
Talk Web Design: Get Ready For CSS Grid Layout by Rachel Andrew
Talk Web Design: Get Ready For CSS Grid LayoutTalk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid Layout
Rachel Andrew4.9K views
Frontend United: Start using CSS Grid Layout today! by Rachel Andrew
Frontend United: Start using CSS Grid Layout today!Frontend United: Start using CSS Grid Layout today!
Frontend United: Start using CSS Grid Layout today!
Rachel Andrew2.2K views
Render Conf: Start using CSS Grid Layout Today by Rachel Andrew
Render Conf: Start using CSS Grid Layout TodayRender Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout Today
Rachel Andrew3.6K views
Laracon Online: Grid and Flexbox by Rachel Andrew
Laracon Online: Grid and FlexboxLaracon Online: Grid and Flexbox
Laracon Online: Grid and Flexbox
Rachel Andrew1.9K views
AEA Chicago CSS Grid Layout by Rachel Andrew
AEA Chicago CSS Grid LayoutAEA Chicago CSS Grid Layout
AEA Chicago CSS Grid Layout
Rachel Andrew1.6K views
Making the most of New CSS Layout by Rachel Andrew
Making the most of New CSS LayoutMaking the most of New CSS Layout
Making the most of New CSS Layout
Rachel Andrew1.3K views
What I discovered about layout vis CSS Grid by Rachel Andrew
What I discovered about layout vis CSS GridWhat I discovered about layout vis CSS Grid
What I discovered about layout vis CSS Grid
Rachel Andrew9.5K views

Similar to The New CSS Layout - Dutch PHP Conference

GOTO Berlin - You can use CSS for that by
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatRachel Andrew
1.3K views110 slides
Confoo: You can use CSS for that! by
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Rachel Andrew
1.5K views109 slides
Next-level CSS by
Next-level CSSNext-level CSS
Next-level CSSRachel Andrew
2.7K views109 slides
The Creative New World of CSS by
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSSRachel Andrew
2K views144 slides
The Future State of Layout by
The Future State of LayoutThe Future State of Layout
The Future State of LayoutStephen Hay
3.2K views88 slides
Highly Maintainable, Efficient, and Optimized CSS by
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSZoe Gillenwater
1.1K views54 slides

Similar to The New CSS Layout - Dutch PHP Conference(20)

GOTO Berlin - You can use CSS for that by Rachel Andrew
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for that
Rachel Andrew1.3K views
Confoo: You can use CSS for that! by Rachel Andrew
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!
Rachel Andrew1.5K views
The Creative New World of CSS by Rachel Andrew
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSS
Rachel Andrew2K views
The Future State of Layout by Stephen Hay
The Future State of LayoutThe Future State of Layout
The Future State of Layout
Stephen Hay3.2K views
Highly Maintainable, Efficient, and Optimized CSS by Zoe Gillenwater
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSS
Zoe Gillenwater1.1K views
CSS Frameworks by Mike Crabb
CSS FrameworksCSS Frameworks
CSS Frameworks
Mike Crabb635 views
2D Page Layout by Unfold UI
2D Page Layout2D Page Layout
2D Page Layout
Unfold UI632 views
Designing Your Next Generation Web Pages with CSS3 by Gil Fink
Designing Your Next Generation Web Pages with CSS3Designing Your Next Generation Web Pages with CSS3
Designing Your Next Generation Web Pages with CSS3
Gil Fink695 views
CSS pattern libraries by Russ Weakley
CSS pattern librariesCSS pattern libraries
CSS pattern libraries
Russ Weakley83.8K views
CSS Grid Layout by Rachel Andrew
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
Rachel Andrew128.2K views
Start Using CSS Grid Layout Today - RuhrJS by Rachel Andrew
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJS
Rachel Andrew990 views
Advanced sass/compass by Nick Cooley
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
Nick Cooley6.1K views
New Elements & Features in CSS3 by Jamshid Hashimi
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3
Jamshid Hashimi19.8K views

More from Rachel Andrew

All Day Hey! Unlocking The Power of CSS Grid Layout by
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
2.2K views113 slides
SmashingConf SF: Unlocking the Power of CSS Grid Layout by
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
2.3K views113 slides
Unlocking the Power of CSS Grid Layout by
Unlocking the Power of CSS Grid LayoutUnlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid LayoutRachel Andrew
2K views113 slides
Into the Weeds of CSS Layout by
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS LayoutRachel Andrew
1.5K views93 slides
Solving Layout Problems with CSS Grid & Friends - DevFest17 by
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Rachel Andrew
2.1K views96 slides
Graduating to Grid by
Graduating to GridGraduating to Grid
Graduating to GridRachel Andrew
1.6K views143 slides

More from Rachel Andrew(20)

All Day Hey! Unlocking The Power of CSS Grid Layout by Rachel Andrew
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
Rachel Andrew2.2K views
SmashingConf SF: Unlocking the Power of CSS Grid Layout by Rachel Andrew
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
Rachel Andrew2.3K views
Unlocking the Power of CSS Grid Layout by Rachel Andrew
Unlocking the Power of CSS Grid LayoutUnlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid Layout
Rachel Andrew2K views
Into the Weeds of CSS Layout by Rachel Andrew
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS Layout
Rachel Andrew1.5K views
Solving Layout Problems with CSS Grid & Friends - DevFest17 by Rachel Andrew
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17
Rachel Andrew2.1K views
View Source London: Solving Layout Problems with CSS Grid & Friends by Rachel Andrew
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
Rachel Andrew1K views
DevFest Nantes - Start Using CSS Grid Layout today by Rachel Andrew
DevFest Nantes - Start Using CSS Grid Layout todayDevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout today
Rachel Andrew1.1K views
404.ie: Solving Layout Problems with CSS Grid & Friends by Rachel Andrew
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
Rachel Andrew909 views
Solving Layout Problems with CSS Grid & Friends - WEBU17 by Rachel Andrew
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17
Rachel Andrew902 views
Laying out the future with grid & flexbox - Smashing Conf Freiburg by Rachel Andrew
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
Rachel Andrew2.4K views
Solving Layout Problems with CSS Grid & Friends - NordicJS by Rachel Andrew
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJS
Rachel Andrew2.7K views
Google Developers Experts Summit 2017 - CSS Layout by Rachel Andrew
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout
Rachel Andrew1.4K views
Web Summer Camp Keynote by Rachel Andrew
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp Keynote
Rachel Andrew1.9K views
New CSS Layout Meets the Real World by Rachel Andrew
New CSS Layout Meets the Real WorldNew CSS Layout Meets the Real World
New CSS Layout Meets the Real World
Rachel Andrew864 views
An Event Apart DC - New CSS Layout meets the Real World by Rachel Andrew
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
Rachel Andrew408 views
Perch, Patterns and Old Browsers by Rachel Andrew
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old Browsers
Rachel Andrew1.8K views
Evergreen websites for Evergreen browsers by Rachel Andrew
Evergreen websites for Evergreen browsersEvergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsers
Rachel Andrew1.5K views
Where does CSS come from? by Rachel Andrew
Where does CSS come from?Where does CSS come from?
Where does CSS come from?
Rachel Andrew2.8K views

Recently uploaded

TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
21 views15 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 slide
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdfDr. Jimmy Schwarzkopf
20 views29 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
300 views20 slides
Zero to Automated in Under a Year by
Zero to Automated in Under a YearZero to Automated in Under a Year
Zero to Automated in Under a YearNetwork Automation Forum
15 views23 slides
Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
14 views1 slide

Recently uploaded(20)

TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab21 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10300 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely25 views
Powerful Google developer tools for immediate impact! (2023-24) by wesley chun
Powerful Google developer tools for immediate impact! (2023-24)Powerful Google developer tools for immediate impact! (2023-24)
Powerful Google developer tools for immediate impact! (2023-24)
wesley chun10 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson92 views
Serverless computing with Google Cloud (2023-24) by wesley chun
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)
wesley chun11 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
Fwdays17 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc11 views

The New CSS Layout - Dutch PHP Conference

  • 1. The New CSS Layout Rachel Andrew Dutch PHP Conference, 2015
  • 3. The trouble with CSS layout • Floats and clearfix hacks • Absolute positioning means elements are taken out of document flow and risk overlaps • Redundant markup and positioning oddities with display: table • White space issues with inline-block
  • 4. The cost of taming layout methods • Developer hours spent learning non-obvious concepts. • Compromises in terms of document semantics in order to achieve responsive layouts. • Needing to lean on frameworks to help with complex math. • Adding markup to create grids • Using preprocessors to abstract layout hacks
  • 7. In my HTML I have an article with a class of ‘main’. <article class="main"> <h1>Blanchard Crosses the Sea in a Balloon</h1> <p> ... </p> </article>
  • 9. Use the property column- width to declare a width for our columns. The browser will create as many columns as possible using that as the ideal width. .main { column-width: 220px; }
  • 11. CSS Multiple column layout [The column-width value] describes the optimal column width. The actual column width may be wider (to fill the available space), or narrower (only if the available space is smaller than the specified column width). Specified values must be greater than 0.
  • 12. Set the property column- count to 3 and the browser will always create three columns. .main { column-count: 3; }
  • 13. The gap between columns is controlled by the column-gap property. Give this a value of 0 and you have no gap. .main { column-count: 3; column-gap: 0; }
  • 15. The browser takes the column-gap into account when calculating the size of the columns. .main { column-count: 3; column-gap: 20px; }
  • 16. Styling columns • very limited in the current specification • cannot set size of an individual column • cannot change background colour of a column • cannot set padding or margins on a column
  • 17. Multiple column layout future specifications may add additional functionality. For example, columns of different widths and different backgrounds may be supported.
  • 18. Add a rule between columns using the column-rule property. This is a shorthand for: column-rule-width column-rule-style column-rule-color These properties behave just like the border properties. .main { column-count: 3; column-gap: 20px; column-rule: 2px dotted #ccc; }
  • 21. The property column- span can have a value of all or none. If set to all the element will span all columns. .main h1, .image { column-span: all; }
  • 23. Use multiple column layout to tidy up the display of small UI elements.
  • 25. Resources Dev.Opera: https://dev.opera.com/articles/css3-multi-column-layout/ MDN: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_multi- column_layouts CSS Tricks: https://css-tricks.com/guide-responsive-friendly-css-columns/ Multi-column generator: http://aaronlumsden.com/multicol/
  • 28. Navigation marked up as an unordered list in my HTML. <nav> <ul class="nav"> <li><a href="">Introduction</a></li> <li><a href="">Ancient Times</a></li> <li><a href="">Balloon Theory</a></li> <li><a href="">First Public Trial</a></ li> <li><a href="">Experiments</a></li> </ul> </nav>
  • 30. flex is a new value of the display property. This causes the element to use flexbox. justify-content lets us set how the content is justified. nav ul{ display: flex; justify-content: space-between; }
  • 32. To have equal space all around the item give justify-content a value of space-around. nav ul{ display: flex; justify-content: space-around; }
  • 34. Default flexbox behaviour • Items displayed as a row • Items displayed in natural (DOM) order • align-items set to stretch • flex-wrap set to nowrap
  • 35. The flex-direction property. - row - row-reverse - column - column-reverse nav ul{ display: flex; justify-content: space-around; flex-direction: row; }
  • 36. The flex-direction property. - row - row-reverse - column - column-reverse nav ul{ display: flex; justify-content: space-around; flex-direction: row-reverse; }
  • 38. The flex-direction property. - row - row-reverse - column - column-reverse nav ul{ display: flex; justify-content: space-around; flex-direction: column; }
  • 40. The align-items property: - flex-start - flex-end - center - baseline - stretch nav ul{ display: flex; justify-content: space-between; align-items: flex-end; }
  • 44. Our boxes are displayed using flexbox. If there is not space for all 3 they will wrap as the flex-wrap property is set to wrap. .boxes { display: flex; flex-wrap: wrap; justify-content: space-around; } .box { border: 1px solid #444; padding: 10px; margin: 10px; flex-grow: 1; flex-shrink: 1; flex-basis: 200px; min-width: 1px; }
  • 45. The flex property is a shorthand for the three properties. Initial values as follows: flex-grow: 0; flex-shrink: 1; flex-basis: auto; .boxes { display: flex; flex-wrap: wrap; justify-content: space-around; } .box { border: 1px solid #444; padding: 10px; margin: 10px; flex: 1 1 200px; min-width: 1px; }
  • 46. Giving the box with a class of .box2 a flex-grow value of 2. The other boxes have flex-grow set to 1. .box2 { flex-grow: 2; }
  • 48. Use the order property to change the order of flex items. .box1 { order: 3; } .box2 { flex-grow: 2; order: 1; } .box3 { order: 2; }
  • 50. Resources Solved by Flexbox: http://philipwalton.github.io/solved-by-flexbox/ CSS Tricks: https://css-tricks.com/snippets/css/a-guide-to-flexbox/ Flexbox Cheat Sheet: http://www.sketchingwithcss.com/samplechapter/ cheatsheet.html Flexbox in 5: http://flexboxin5.com/ Useful information on supporting older browsers: http://www.planningforaliens.com/blog/2014/03/11/real-world-flexbox/ http://zomigi.com/downloads/Leveling-Up-With-Flexbox_SmashingConf_140319.pdf
  • 55. We have floated our image left. .shape { float: left; width: 150px; height: 150px; margin: 20px; }
  • 56. Add the property shape- outside with a value of circle(50%). .shape { float: left; width: 150px; height: 150px; margin: 20px; shape-outside: circle(50%); }
  • 60. Basic Shapes • inset() • circle() • ellipse() • polygon()
  • 61. Using the polygon value for shape-inside. The polygon requires at least 3 sets of x, y coordinates. .shape { float: left; width: 200px; height: 200px; margin-top: 10px; } .shape-polygon { shape-outside: polygon(0 20px, 160px 40px, 180px 70px, 180px 120px, 120px 200px, 60px 210px, 0 220px); }
  • 63. Shapes from the Alpha Channel
  • 65. My HTML contains an image along with some text. <div class="s-box"> <img src="noun_109069.png" alt="" width="200" class="shape shape-image”> <p> ... </p> </div>
  • 66. To use an alpha channel pass in a URL for your image and a threshold for the transparency. .shape-image { shape-outside: url('noun_109069.png'); shape-image-threshold: 0.5; }
  • 68. Use an image in generated content to shape your text. .content:before { content: ""; float: left; width: 200px; height: 200px; shape-outside: url('alpha.png'); shape-image-threshold: 0.5; }
  • 70. What’s next for Shapes? • shape-inside - text flowing inside a shape • shapes defined on elements that are not floated • shape-padding property • Level 2 specification http://dev.w3.org/csswg/ css-shapes-2
  • 71. Resources How to Get Started with CSS Shapes: http://www.webdesignerdepot.com/2015/03/ how-to-get-started-with-css-shapes/ A List Apart: http://alistapart.com/article/css-shapes-101 HTML5 Rocks: http://www.html5rocks.com/en/tutorials/shapes/getting-started/ How to prepare images using Photoshop: http://blogs.adobe.com/webplatform/ 2014/03/11/add-shape-and-depth-to-your-layout-with-photoshop-and-css-shapes/ Adobe: http://webplatform.adobe.com/shapes/
  • 74. Browser Support All my examples work in Chrome unprefixed - you need to enable the Experimental Web Platform Features flag. You can also use Webkit nightlies, with the -webkit prefix. The work in Blink and Webkit is being done by Igalia, sponsored by Bloomberg. IE10 and up has support for the old syntax, with an -ms prefix. Mozilla are currently implementing Grid in Firefox. There is a Polyfill under active development: https://github.com/ FremyCompany/css-grid-polyfill/
  • 75. Our HTML consists of a div with a class of wrapper and six child elements. <div class="wrapper"> <div class="a">A</div> <div class="b">B</div> <div class="c">C</div> <div class="d">D</div> <div class="e">E</div> <div class="f">F</div> </div>
  • 76. To create a grid we use a new value of the display property. display: grid .wrapper { display: grid; }
  • 77. We describe the grid using the new properties: grid-template-columns grid-template-rows .wrapper { display: grid; grid-template-columns: 100px 10px 100px 10px 100px; grid-template-rows: auto 10px auto; }
  • 78. We position items using the new properties: grid-column-start
 grid-column-end
 grid-row-start
 grid-row-end .a { grid-column-start: 1; grid-column-end: 2; grid-row-start: 1; grid-row-end: 2; }
  • 79. To position an item bottom centre, I start at column line 3, this is the line after the gutter track. .b { grid-column-start: 3; grid-column-end: 4; grid-row-start: 3; grid-row-end: 4; }
  • 80. To span more tracks we just change the end row or column line. .b { grid-column-start: 3; grid-column-end: 6; grid-row-start: 3; grid-row-end: 4; }
  • 81. The longhand for line- based placement means up to 4 properties to position each element. .a { grid-column-start: 1; grid-column-end: 2; grid-row-start: 1; grid-row-end: 2; } .b { grid-column-start: 3; grid-column-end: 4; grid-row-start: 3; grid-row-end: 4; }
  • 82. Declare start and end values with grid-column and grid-row. Values are separated by a / symbol. .a { grid-column: 1 / 2; grid-row: 1 / 2; } .b { grid-column: 3 / 6; grid-row: 3 / 4; }
  • 83. Declare all 4 values using the grid-area property. .a { grid-area: 1 / 1 / 2 / 2; } .b { grid-area: 3 / 3 / 4 / 6; }
  • 85. Grid Lines Lines can be horizontal or vertical. They are referred to by number and can be named. Highlighted is Column Line 2.
  • 86. Grid Track A Grid Track is the space between two Grid Lines. Tracks can be horizontal or vertical (rows or columns). The highlighted Grid Track is between Row Lines 2 and 3.
  • 87. Grid Cell The smallest unit on our grid, a Grid Cell is the space between four Grid Lines. It’s just like a table cell. The highlighted Grid Cell is between row lines 2 and 3 and column lines 2 and 3.
  • 88. Grid Area Any area of the Grid bound by 4 Grid Lines. It can contain many Grid Cells. The highlighted Grid Area is between row lines 1 and 3, column lines 2 and 4.
  • 89. All examples can be found at http://gridbyexample.com. Use Chrome. Enable “Experimental Web Platform Features” flag.
  • 92. The HTML around my page content. The various areas of my page are child elements of a div with a class of wrapper. <div class="wrapper"> <header class="mainheader"></header> <div class="panel"></div> <div class="content"></div> </div>
  • 94. Declaring a grid on wrapper. The grid has three columns, and four rows. .wrapper { width: 100%; max-width: 960px; margin: 0 auto; display: grid; grid-template-columns: 30% 5% 65%; grid-template-rows: 40px auto 20px auto; }
  • 96. Positioning our elements using the grid-column and grid-row shorthand. This is all we need to do to create our layout. .mainheader { grid-column: 1 / 4; grid-row: 2 / 3; } .panel { grid-column: 1 / 2; grid-row: 4 / 5; } .content { grid-column: 3 / 4; grid-row: 4 / 5; }
  • 99. I can add a footer to this layout. <div class="wrapper"> <header class="mainheader"></header> <div class="panel"></div> <div class="content"></div> <footer class="mainfooter"></footer> </div>
  • 100. Positioning the footer between row lines five and six. .mainfooter { grid-column: 1 / 4; grid-row: 5 / 6; }
  • 102. Our grid only has 5 row lines specified - yet we placed an item between row lines 5 and 6. Grid creates an implicit grid line for us. .wrapper { display: grid; grid-template-columns: 30% 5% 65%; grid-template-rows: 40px auto 20px auto; } .mainfooter { grid-column: 1 / 4; grid-row: 5 / 6; }
  • 103. Grid lines can be explicit or implicit • Explicit grid lines are those specified using grid- template-rows or grid-template-columns. • Implicit lines are created when you place something into a row or column track outside of the explicit grid. • Default behaviour is those tracks are auto sized. You can specify a size with the grid-auto- columns and grid-auto-rows properties.
  • 104. Grid is “table like” however … • Unlike a table for layout Grid does not rely on your content being a particular order in the source.
 • Being entirely described in CSS we can move things around the Grid at different breakpoints, introduce or redefine a Grid for any breakpoint.
  • 105. Using Grid to order the page elements in a single column for narrow screen widths. .wrapper { display: grid; grid-template-rows: 10px auto 10px auto 10px auto 10px auto; } .mainheader { grid-row: 2 / 3; } .content { grid-row: 4 / 5; } .panel { grid-row: 6 / 7; } .mainfooter { grid-row: 8 / 9; }
  • 107. Redefine the Grid at min- width 550 pixels. Position items as in the earlier example. @media (min-width: 550px) { .wrapper { grid-template-columns: 30% 5% 65%; grid-template-rows: 40px auto 20px auto 20px auto; } .mainheader { grid-column: 1 / 4; grid-row: 2 / 3; } .panel { grid-column: 1 / 2; grid-row: 4 / 5; } .content { grid-column: 3 / 4; grid-row: 4 / 5; } .mainfooter { grid-column: 1 / 4; grid-row: 6 / 7; } }
  • 110. We assign a name to the elements on our page. I am doing this outside of any Media Queries. .mainheader { grid-area: header; } .content { grid-area: content; } .panel { grid-area: sidebar; } .mainfooter { grid-area: footer; }
  • 111. Describe the layout on the parent element using the grid-template-areas property. A period “.” indicates that this grid cell is empty. .wrapper { display: grid; grid-template-rows: 10px auto 10px auto 10px auto 10px auto; grid-template-areas: "." "header" "." "content" "." "sidebar" "." "footer"; }
  • 114. Redefining the template areas for the wider layout. @media (min-width: 550px) { .wrapper { grid-template-columns: 30% 5% 65%; grid-template-rows: 2em auto 1em auto 1em auto; grid-template-areas: ". . ." "header header header" ". . ." "sidebar . content" ". . ." "footer footer footer" } }
  • 117. Resources Grid by Example: http://gridbyexample.com Examples from Igalia: http://igalia.github.io/css-grid-layout/ An article covering the original IE10 implementation: http://24ways.org/2012/css3- grid-layout/
  • 120. Floated items always rise to the top. We can wrap text around the right or left and bottom of an item.
  • 121. Exclusions enable wrapping text around all sides of an item.
  • 122. I have an article with an image as the last child in the source. The image has a class of exclusion. <article> <p> ... </p> <img src="balloons3.jpg" alt="Hot air balloons" class="exclusion" /> </article>
  • 123. The article has been given position relative to create a positioning context. I have then positioned the image using absolute positioning. .main { position:relative; } .exclusion { position: absolute; top: 14em; left: 14em; width: 320px; }
  • 125. The wrap-flow property means that the text will respect the positioned element and wrap round both sides. I’m using the -ms prefix given this is only implemented in IE browsers. .main { position:relative; } .exclusion { position: absolute; top: 14em; left: 14em; width: 320px; -ms-wrap-flow: both; }
  • 130. Regions were in the Blink engine but removed in January 2014. They are still part of Safari desktop and iOS. https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/kTktlHPJn4Q/YrnfLxeMO7IJ
  • 131. I have an article contained inside an article element. Below that is a set of empty elements, each with a class of article- regions. <article class="main content”> <p> ... </p> </article> <div class="region1 article-regions"></div> <div class="regionwrapper"> <div class="region2 article-regions"></div> <div class="region3 article-regions"></div> <div class="region4 article-regions"></div> </div> <div class="region5 article-regions"></div>
  • 133. We flow the content of our article into ‘article- thread’. This is a name we have given the content. We then flow the content into .article-regions - this is the class we gave our empty elements. .main { flow-into: article-thread; } .article-regions { flow-from: article-thread; }
  • 134. Positioning the empty elements. .region1 { height: 10em; } .regionwrapper { display: flex; flex-direction: row; } .region2 { flex: 1; padding: 10px; height: 10em; } .region3 { flex: 1; padding: 10px; height: 10em; } .region4 { flex: 1; padding: 10px; height: 10em; } .region5 { padding: 10px; }
  • 136. Resources An Introduction to CSS Regions: https://dev.opera.com/articles/introduction-to-css- regions/ Use CSS Regions to flow content through a layout: https://docs.webplatform.org/wiki/ tutorials/css-regions Say Hello to CSS Regions Polyfill: http://corlan.org/2013/02/08/say-hello-to-css- regions-polyfill/ Introducing CSS Regions: http://www.webdesignerdepot.com/2013/09/introducing- css-regions/