SlideShare a Scribd company logo
The Future of
                        CSS Layout
October 22, 2012         by Zoe Mickley Gillenwater
Future of Web Design                      @zomigi
                                        zomigi.com
What I do
      Books                         Web
      Stunning CSS3:                Accessibility
      A Project-based Guide to      specialist at AT&T
      the Latest in CSS
                                    Visual designer
      www.stunningcss3.com
                                    CSS developer
                                    and consultant
      Flexible Web Design:
      Creating Liquid and Elastic
      Layouts with CSS
      www.flexiblewebbook.com

                                                         2
the past
table layout



               3
Problems with table layout
•   Complicated/bulky markup
•   Accessibility problems
•   Slower browser rendering
•   Rigid designs
•   Spacer gifs




                               4
the present
 float layout



                5
Advantages of floats in layout
• Less HTML than tables
• More flexibility to change layout than tables
• Can change visual order to not match
  HTML (somewhat)
• Other content aware of floats' presence
• Can use clear to get blocks out of the way




                                                  6
Problems with float layout
• Visual location tied to HTML order
  (somewhat)
• Wrapping/float drop
• Difficulty with containment
• Difficulty with equal-height columns
• No float:center




                                         7
?
 what are the
alternatives



                8
Alternative: display inline-block


                                         
                                                 *

*   only partial support in IE 7 and 6


                                                 9
I wish my parents
would stop treating
 me like I’m inline.
Can’t they see I’m a
     block now?




                       10
Use: centered nav bar
nav ul {
  margin: 0;
  padding: 0;
  border-bottom: 3px solid #fff;
   list-style: none;
   text-align: center; }
nav li {
   display: inline-block;
   vertical-align: bottom;
   margin: 0 .2em;
   padding: .3em .5em; ... }
                                   11
Use: centered nav bar




•   List horizontally centered
•   Links aligned on bottom
•   Links have top and bottom padding
•   Links can be different heights
•   List contains links (see its bottom border)
                                                  12
Alternative: display table-cell


                                 
                                         *

*   only in IE 8 and later


                                         13
How table display works
• Makes boxes act like table equivalents
  • Example: boxes with display:table-cell
    act like <td> and sit on same line
• Good for grid-like layouts
• Disadvantage: tied to HTML order




                                             14
Use: hybrid fixed-fluid layout
section {
   display: table;
   table-layout: fixed;
   width: 100%; }
article {
   display: table-cell;
   padding: 10px;
   vertical-align: top; }
article.fixed {
   width:250px; }


                                 15
Use: hybrid fixed-fluid layout




                                 16
the future
a whole bunch of CSS3



                        17
CSS3 “content-flow” modules
• Multi-column Layout: flow a box’s content
  into multiple columns in that box
• Regions: flow content into multiple,
  separate boxes
• Exclusions and Shapes: make content
  flow around and within areas in more
  intricate ways than floating



                                              18
Grid Template Layout
http://dev.w3.org/csswg/css3-layout/


      X            X   X      X        10


                                            *

*   with -ms- prefix

                                            19
How grid template works
Define invisible grid of rows and columns
and specify which pieces of content go into
which “slot”

body {
  grid: "a a a a"                   a
        "b c c d"
}                              b   c    d
nav     {   flow:   a   }
#main   {   flow:   c   }
aside   {   flow:   d   }
#news   {   flow:   b   }
                                              20
How grid template works
Define invisible grid of rows and columns
and specify which pieces of content go into
which “slot”

body {
  grid: "c d"                  c       d
         "b b"
         "a a"           
}
                                   b
nav    { flow:   a   }
#main { flow:    c   }
aside { flow:    d   }
#news { flow:    b   }             a
                                              21
How grid template works
Use ::slot to style slots with:
•   overflow             •   background properties
•   margin properties    •   column properties
•   padding properties   •   vertical-align
•   border properties    •   writing-mode
•   box-shadow           •   direction
•   box-decoration-break

For example: body::slot(c) {
               background: #7FD13B;
               vertical-align: top;
             }
                                                     22
Flexible Box Layout
www.w3.org/TR/css3-flexbox/


     21            X           12.1       X      X
                           †
           *

*
†
    with -webkit- prefix
    can be switched on in version 18 nightlies
                                                     23
How flexbox works
• Make boxes automatically grow to fill
  space or shrink to avoid overflow
• Give boxes proportional measurements
• Lay out boxes in any direction
• Align boxes on any side
• Place boxes out of order from HTML




                                          24
Let’s try
flexbox
out on
this page




            25
Original CSS




.feature {
   float: left;
  width: 30%;
  margin: 0 4.5% 0 0;
  padding: 130px 0 0 0;
}
                          26
Create a flex container
<div id="features-wrapper">
   <div class="feature" id="feature-candy">
     ...</div>
   <div class="feature" id="feature-pastry">
     ...</div>
   <div class="feature" id="feature-dessert">
     ...</div>
</div>
                         Make sure to add the
#features-wrapper {      -moz, -ms, and -webkit
                         prefixed values and
   display: flex;        properties in real life!
}                                                 27
Specify direction of flex items
#features-wrapper {
   display: flex;
   flex-direction: row;                 default value
}

Could switch to vertical stacking in mobile/narrow-screen
media query:
#features-wrapper {
   display: flex;
   flex-direction: column;
}

                                                            28
Make flex items flexible
.feature {
   flex: 1 1 0px;
   margin-right: 40px;
  padding: 130px 0 0 0; }




                            29
Make flex items flexible
.feature {
   flex: 1 1 0px;
   margin-right: 40px;      flex basis
  padding: 130px 0 0 0; }
                            flex shrink factor
Same as:
                            flex grow factor
.feature {
  flex: 1;
  margin-right: 40px;
  padding: 130px 0 0 0; }


                                                 30
Add a fourth feature box
<div id="features-wrapper">
   <div class="feature" id="feature-candy">
     ...</div>
   <div class="feature" id="feature-pastry">
     ...</div>
   <div class="feature" id="feature-dessert">
     ...</div>
  <div class="feature" id="feature-bread">
     ...</div>
</div>


                                                31
All boxes adjust in width




                            32
Don’t need to do this anymore
.2up .feature { width: 45%; ... }
.3up .feature { width: 30%; ... }
.4up .feature { width: 22%; ... }




                                    33
Highlight a sale category
.sale {
   padding: 130px 20px 20px 20px;
   border-radius: 3px;
   background-color: hsla(0,0%,100%,.4);
}


What percentage width would I set to make
this twice as wide as other boxes, if I weren’t
using flex?

                                                  34
Make sale box twice as wide




.sale {
  flex: 2;
  padding: 130px 20px 20px 20px;
  border-radius: 3px;
  background-color: hsla(0,0%,100%,.4);
}
                                          35
Default equal-height columns!
#features-wrapper {
  display: flex;
  align-items: stretch;
}


This is the default value, so we don’t need to
actually set this property, but this shows you
what it looks like.


                                                 36
Vertical centering with ease!




#features-wrapper {
  display: flex;
  align-items: center;
}
                                37
Visual order = HTML order




                            38
Move sale box to front of line
.sale {
  order: -1;
  flex: 2;
  padding: 130px 20px 20px 20px;
  border-radius: 3px;
  background-color: hsla(0,0%,100%,.4);
}


Default order value is 0 for all flex items, so
-1 moves this one before others
                                                  39
New visual order, same HTML




                              40
Accessibility implications
• Pro: keep content in logical order in HTML
  instead of structuring HTML to achieve
  visual layout
• Con: focus/tab order won’t always match
  expected order, may jump around
  seemingly randomly




                                               41
Columns are too narrow




                         42
Create multi-line flex container
#features-wrapper {
  display: flex;
  flex-wrap: wrap;         Allow children flex items
                           to wrap to multiple lines
}
.sale {
  order: -1;               Make box fill line
  flex: 1 1 100%;          Remove gap to right,
  margin: 0 0 20px 0;      add space below
  padding: 130px 20px 20px 20px;
  border-radius: 3px;
  background-color: hsla(0,0%,100%,.4);
}                                                    43
Flex items can now wrap




                          44
Change icon position
.sale {
  order: -1;
  flex: 1 1 100%;
  margin: 0 0 20px 0;
  padding: 20px 20px 1px 170px;
  border-radius: 3px;
  background-color: hsla(0,0%,100%,.4);
  background-position: 20px 0;
}



                                          45
Final layout




               46
use flexbox now for
progressive enhancement
            
                          47
How can I make this form:
• Display on a single line with image
• Vertically centered with image
• Span full-width of container




                                        48
Inline-block achieves:
Display on a single line with image
Vertically centered with image
X Span full-width of container




                                       49
Different units make life hard
  Pixels
  Ems
  Some mystery percentage




                                 50
Make the text input flex
#order, #order form {       Make outer div and form
   display: flex;           into flex containers
   align-items: center; }   Vertically center kiddos
#order form {
                            Make form take up all
   flex: 1; }               space next to image
#order #message {
                            Make text input take up
   flex: 1;                 all space in form left
   min-width: 7em;          after label and button
  margin: 0 5px; }          But don’t let it get crazy-
                            small


                                                          51
Use inline-block with flexbox




                                52
Use inline-block with flexbox
#order img, #order form {
  display: inline-block;
  vertical-align: middle; }
#order, #order form {
   display: flex;
   align-items: center; }
#order form {
   flex: 1; }
#order #message {
   flex: 1;
   min-width: 7em;
  margin: 0 5px; }              53
Full-width nav bar




nav ul {              nav li {
  display: table;       display: table-cell;
  width: 100%;          text-align: center; }
  margin: 0;
  padding: 0;
  list-style: none; }
                                            54
Not so hot with no backgrounds
            Uneven spacing




          Don’t like these gaps


                                  55
Even spacing with flexbox




nav ul {
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding: 0;
  list-style: none; }
                                    56
Use inline-block with flexbox




                                57
Use inline-block with flexbox
nav ul {
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: center;
}
nav li {
   display: inline-block;
}
                                    58
Or use Modernizr script
http://modernizr.com
nav ul {               nav li {
   display: table;        display: table-cell;
   width: 100%;        }
   margin: 0;          .flexbox nav li {
   padding: 0;            display: list-item;
   list-style: none;   }
}
.flexbox nav ul {
   display: flex;
}
                                             59
go forth and
practice
    
               60
Learn more
Download slides and get links at
http://zomigi.com/blog/future-css-layout-fowd




Zoe Mickley Gillenwater
@zomigi
design@zomigi.com
zomigi.com | stunningcss3.com | flexiblewebbook.com

Title photo by Gilderic Photography (http://www.flickr.com/photos/gilderic/6885830288/)
Rocket designed by Jason Peters from The Noun Project                                     61

More Related Content

PDF
Flexbox and Grid Layout
Rachel Andrew
 
PDF
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
Morten Rand-Hendriksen
 
PDF
CSS3 Layout
Zoe Gillenwater
 
PDF
The New CSS Layout - dotCSS
Rachel Andrew
 
PDF
Grids of Tomorrow: CSS Grid Layout
Simone Lelli
 
PDF
The New CSS Layout - Dutch PHP Conference
Rachel Andrew
 
PDF
Future Layout & Performance
Rachel Andrew
 
PDF
ConFoo 2016: Making Sense of CSS Layout
Rachel Andrew
 
Flexbox and Grid Layout
Rachel Andrew
 
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
Morten Rand-Hendriksen
 
CSS3 Layout
Zoe Gillenwater
 
The New CSS Layout - dotCSS
Rachel Andrew
 
Grids of Tomorrow: CSS Grid Layout
Simone Lelli
 
The New CSS Layout - Dutch PHP Conference
Rachel Andrew
 
Future Layout & Performance
Rachel Andrew
 
ConFoo 2016: Making Sense of CSS Layout
Rachel Andrew
 

What's hot (20)

PDF
CSS Grid Layout for Topconf, Linz
Rachel Andrew
 
PDF
An Event Apart SF: CSS Grid Layout
Rachel Andrew
 
PDF
Flexbox and Grid Layout
Rachel Andrew
 
PDF
Fluent: Making Sense of the New CSS Layout
Rachel Andrew
 
PDF
But what about old browsers?
Rachel Andrew
 
PDF
CSS Day: CSS Grid Layout
Rachel Andrew
 
PDF
Laracon Online: Grid and Flexbox
Rachel Andrew
 
PDF
Talk Web Design: Get Ready For CSS Grid Layout
Rachel Andrew
 
PDF
Evergreen websites for Evergreen browsers
Rachel Andrew
 
PDF
An Event Apart Seattle - New CSS Layout Meets the Real World
Rachel Andrew
 
PDF
Confoo: You can use CSS for that!
Rachel Andrew
 
PDF
CSS Grid vs. Flexbox
Ecaterina Moraru (Valica)
 
PDF
What I discovered about layout vis CSS Grid
Rachel Andrew
 
PDF
CSS Grid Layout: An Event Apart Boston 2016
Rachel Andrew
 
PDF
GOTO Berlin - You can use CSS for that
Rachel Andrew
 
PDF
CSS Grid
Digital Surgeons
 
PDF
CSS Conf Budapest - New CSS Layout
Rachel Andrew
 
PDF
Devoxx Belgium: CSS Grid Layout
Rachel Andrew
 
PDF
CSS Grid Layout
Rachel Andrew
 
PDF
Making the most of New CSS Layout
Rachel Andrew
 
CSS Grid Layout for Topconf, Linz
Rachel Andrew
 
An Event Apart SF: CSS Grid Layout
Rachel Andrew
 
Flexbox and Grid Layout
Rachel Andrew
 
Fluent: Making Sense of the New CSS Layout
Rachel Andrew
 
But what about old browsers?
Rachel Andrew
 
CSS Day: CSS Grid Layout
Rachel Andrew
 
Laracon Online: Grid and Flexbox
Rachel Andrew
 
Talk Web Design: Get Ready For CSS Grid Layout
Rachel Andrew
 
Evergreen websites for Evergreen browsers
Rachel Andrew
 
An Event Apart Seattle - New CSS Layout Meets the Real World
Rachel Andrew
 
Confoo: You can use CSS for that!
Rachel Andrew
 
CSS Grid vs. Flexbox
Ecaterina Moraru (Valica)
 
What I discovered about layout vis CSS Grid
Rachel Andrew
 
CSS Grid Layout: An Event Apart Boston 2016
Rachel Andrew
 
GOTO Berlin - You can use CSS for that
Rachel Andrew
 
CSS Conf Budapest - New CSS Layout
Rachel Andrew
 
Devoxx Belgium: CSS Grid Layout
Rachel Andrew
 
CSS Grid Layout
Rachel Andrew
 
Making the most of New CSS Layout
Rachel Andrew
 
Ad

Viewers also liked (20)

PPT
Html5, css3 and the future of web technologies
Võ Duy Tuấn
 
PDF
CSS Layout
지수 윤
 
PDF
Understanding flex box CSS Day 2016
Davide Di Pumpo
 
PPTX
El futuro del css
SlashMobility.com
 
PPTX
El futuro del css
SlashMobility.com
 
PDF
Enhancing Responsiveness With Flexbox (CSS Day)
Zoe Gillenwater
 
PPTX
Taylor lautner
DanielaZaccaro
 
PPTX
Oso panda
Nelson Colmenarez
 
PPTX
Mario casas
rubia98
 
PPTX
XE 오픈 세미나(2014-06-28) - (1/3) 레이아웃 제작 기본
XpressEngine
 
PDF
4주 CSS Layout
지수 윤
 
PPT
Ansiedad Y Estres
★Jaime Pereira García★
 
PDF
Graph Databases - Where Do We Do the Modeling Part?
DATAVERSITY
 
PPTX
7 Creativity Principles For User Experience Teams
Tom Illmensee
 
PPTX
What is a good technology stack today?
Netlight Consulting
 
PPT
Frames tables forms
nobel mujuji
 
PPT
JavaScript Operators
Charles Russell
 
PPT
Introdution to HTML 5
onkar_bhosle
 
PPTX
Html 5
manujayarajkm
 
KEY
An Introduction to HTML5
Steven Chipman
 
Html5, css3 and the future of web technologies
Võ Duy Tuấn
 
CSS Layout
지수 윤
 
Understanding flex box CSS Day 2016
Davide Di Pumpo
 
El futuro del css
SlashMobility.com
 
El futuro del css
SlashMobility.com
 
Enhancing Responsiveness With Flexbox (CSS Day)
Zoe Gillenwater
 
Taylor lautner
DanielaZaccaro
 
Mario casas
rubia98
 
XE 오픈 세미나(2014-06-28) - (1/3) 레이아웃 제작 기본
XpressEngine
 
4주 CSS Layout
지수 윤
 
Ansiedad Y Estres
★Jaime Pereira García★
 
Graph Databases - Where Do We Do the Modeling Part?
DATAVERSITY
 
7 Creativity Principles For User Experience Teams
Tom Illmensee
 
What is a good technology stack today?
Netlight Consulting
 
Frames tables forms
nobel mujuji
 
JavaScript Operators
Charles Russell
 
Introdution to HTML 5
onkar_bhosle
 
An Introduction to HTML5
Steven Chipman
 
Ad

Similar to The Future of CSS Layout (20)

PPTX
Castro Chapter 11
Jeff Byrnes
 
PPTX
Cascading Style Sheets CSS
Asif Shahzad
 
PDF
#2 - CSS Layouts Overview
iloveigloo
 
PDF
Laying out the future
Chris Mills
 
PDF
css.pdf
AbdulRafayawan
 
PDF
CSS3 Refresher
Ivano Malavolta
 
PPTX
Advanced CSS.pptx
DiyonaVas
 
PDF
Web I - 07 - CSS Frameworks
Randy Connolly
 
PDF
Introduction to CSS3
Doris Chen
 
PDF
Web Layout
Shawn Calvert
 
PPTX
Responsive web design
Richa Goel
 
PDF
Grid and Flexbox - Smashing Conf SF
Rachel Andrew
 
PDF
Dynamic User Interfaces for Desktop and Mobile
peychevi
 
PDF
Render Conf: Start using CSS Grid Layout Today
Rachel Andrew
 
PDF
CSS: a rapidly changing world
Russ Weakley
 
PPTX
How to create a Liquid three column CSS layout
darylslides
 
PPTX
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
ganeshchettipalli
 
PDF
CSS - OOCSS, SMACSS and more
Russ Weakley
 
PDF
Future layouts
Chris Mills
 
PDF
Laying out the future
Rachel Andrew
 
Castro Chapter 11
Jeff Byrnes
 
Cascading Style Sheets CSS
Asif Shahzad
 
#2 - CSS Layouts Overview
iloveigloo
 
Laying out the future
Chris Mills
 
CSS3 Refresher
Ivano Malavolta
 
Advanced CSS.pptx
DiyonaVas
 
Web I - 07 - CSS Frameworks
Randy Connolly
 
Introduction to CSS3
Doris Chen
 
Web Layout
Shawn Calvert
 
Responsive web design
Richa Goel
 
Grid and Flexbox - Smashing Conf SF
Rachel Andrew
 
Dynamic User Interfaces for Desktop and Mobile
peychevi
 
Render Conf: Start using CSS Grid Layout Today
Rachel Andrew
 
CSS: a rapidly changing world
Russ Weakley
 
How to create a Liquid three column CSS layout
darylslides
 
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
ganeshchettipalli
 
CSS - OOCSS, SMACSS and more
Russ Weakley
 
Future layouts
Chris Mills
 
Laying out the future
Rachel Andrew
 

More from Zoe Gillenwater (20)

PDF
Using Flexbox Today (Frontier Conf 2016)
Zoe Gillenwater
 
PDF
Using Flexbox Today (Generate Sydney 2016)
Zoe Gillenwater
 
PDF
Using Flexbox Today (CSS Summit 2016)
Zoe Gillenwater
 
PDF
Using Flexbox Today (Frontend United 2016)
Zoe Gillenwater
 
PDF
Show vs. Tell in UX Design (Front in Amsterdam)
Zoe Gillenwater
 
PDF
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
Zoe Gillenwater
 
PDF
Responsive Flexbox Inspiration (Responsive Day Out)
Zoe Gillenwater
 
PDF
CSS Lessons Learned the Hard Way (ConvergeSE)
Zoe Gillenwater
 
PDF
Enhancing Responsiveness With Flexbox (Smashing Conference)
Zoe Gillenwater
 
PDF
Enhancing Responsiveness with Flexbox (RWD Summit)
Zoe Gillenwater
 
PDF
CSS Lessons Learned the Hard Way (Beyond Tellerand)
Zoe Gillenwater
 
PDF
CSS Lessons Learned the Hard Way (Generate Conf)
Zoe Gillenwater
 
PDF
Leveling Up With Flexbox (Smart Web Conference)
Zoe Gillenwater
 
PDF
Leveling Up with Flexbox (Smashing Conference)
Zoe Gillenwater
 
PDF
Just One (CSS Dev Conference keynote)
Zoe Gillenwater
 
PDF
Putting Flexbox into Practice (Fronteers)
Zoe Gillenwater
 
PDF
Putting Flexbox into Practice
Zoe Gillenwater
 
PDF
Building Responsive Layouts
Zoe Gillenwater
 
PDF
Building Responsive Layouts
Zoe Gillenwater
 
PDF
CSS3, Media Queries, and Responsive Design
Zoe Gillenwater
 
Using Flexbox Today (Frontier Conf 2016)
Zoe Gillenwater
 
Using Flexbox Today (Generate Sydney 2016)
Zoe Gillenwater
 
Using Flexbox Today (CSS Summit 2016)
Zoe Gillenwater
 
Using Flexbox Today (Frontend United 2016)
Zoe Gillenwater
 
Show vs. Tell in UX Design (Front in Amsterdam)
Zoe Gillenwater
 
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
Zoe Gillenwater
 
Responsive Flexbox Inspiration (Responsive Day Out)
Zoe Gillenwater
 
CSS Lessons Learned the Hard Way (ConvergeSE)
Zoe Gillenwater
 
Enhancing Responsiveness With Flexbox (Smashing Conference)
Zoe Gillenwater
 
Enhancing Responsiveness with Flexbox (RWD Summit)
Zoe Gillenwater
 
CSS Lessons Learned the Hard Way (Beyond Tellerand)
Zoe Gillenwater
 
CSS Lessons Learned the Hard Way (Generate Conf)
Zoe Gillenwater
 
Leveling Up With Flexbox (Smart Web Conference)
Zoe Gillenwater
 
Leveling Up with Flexbox (Smashing Conference)
Zoe Gillenwater
 
Just One (CSS Dev Conference keynote)
Zoe Gillenwater
 
Putting Flexbox into Practice (Fronteers)
Zoe Gillenwater
 
Putting Flexbox into Practice
Zoe Gillenwater
 
Building Responsive Layouts
Zoe Gillenwater
 
Building Responsive Layouts
Zoe Gillenwater
 
CSS3, Media Queries, and Responsive Design
Zoe Gillenwater
 

Recently uploaded (20)

PPTX
UCSP-Quarter 1-Week 6-Powerpoint Presentation
EmyMaquiling1
 
PDF
Shape Language for Character Design by Adhec Saputra
Adhec Saputra
 
PPTX
Brown Beige Vintage Style History Project Presentation.pptx
mb3030336
 
PDF
First-Aid.pdfjavaghavavgahavavavbabavabba
meitohehe
 
PDF
neurons-1hhdbbbsjndjnnbbdjndnnndj30501.pdf
Rahul954607
 
PDF
Find Your Target Audience A 6-Step Framework to Grow Your Business.pdf
Zinavo Pvt Ltd
 
PDF
Portfolio Arch Estsabel Chourio - Interiorism,
arqeech
 
PDF
How Neuroscience and AI Inspire Next-Gen Design
Andrea Macruz
 
PDF
URBAN DESIGN DESKTOP CASESTUDY IITG.pdf
kamal lasya
 
PDF
MARIJA CVITKOVAC - GRAPHIC DESIGN PORTFOLIO 2025
marijacvdesign
 
PDF
SS27 Women's Fashion Trend Book Peclers Paris
Peclers Paris
 
PPTX
History of interior design- european and american styles.pptx
MINAKSHI SINGH
 
PPTX
The birth & Rise of python.pptx vaibhavd
vaibhavdobariyal79
 
PDF
slide logistics CONVENIENCE STORES ..pdf
thuphuong0965195082
 
PPTX
KOTA LAMA BANYUMAS.pptxxxxxxxxxxxxxxxxxxxx
pt satwindu utama
 
PPTX
MALURI KISHORE-.pptxdsrhbcdsfvvghhhggggfff
sakthick46
 
PPTX
Landscape assignment for landscape architecture
aditikoshley2
 
PDF
Top 10 UI/UX Design Agencies in Dubai Shaping Digital Experiences
Tenet UI UX
 
PPTX
原版定制TUBS毕业证(布伦瑞克工业大学毕业证书)成绩单修改定制学历成绩单
jicaaeb0
 
PPTX
503ea471-f798-4324-90e8-275bdab41942.pptx
a0999574
 
UCSP-Quarter 1-Week 6-Powerpoint Presentation
EmyMaquiling1
 
Shape Language for Character Design by Adhec Saputra
Adhec Saputra
 
Brown Beige Vintage Style History Project Presentation.pptx
mb3030336
 
First-Aid.pdfjavaghavavgahavavavbabavabba
meitohehe
 
neurons-1hhdbbbsjndjnnbbdjndnnndj30501.pdf
Rahul954607
 
Find Your Target Audience A 6-Step Framework to Grow Your Business.pdf
Zinavo Pvt Ltd
 
Portfolio Arch Estsabel Chourio - Interiorism,
arqeech
 
How Neuroscience and AI Inspire Next-Gen Design
Andrea Macruz
 
URBAN DESIGN DESKTOP CASESTUDY IITG.pdf
kamal lasya
 
MARIJA CVITKOVAC - GRAPHIC DESIGN PORTFOLIO 2025
marijacvdesign
 
SS27 Women's Fashion Trend Book Peclers Paris
Peclers Paris
 
History of interior design- european and american styles.pptx
MINAKSHI SINGH
 
The birth & Rise of python.pptx vaibhavd
vaibhavdobariyal79
 
slide logistics CONVENIENCE STORES ..pdf
thuphuong0965195082
 
KOTA LAMA BANYUMAS.pptxxxxxxxxxxxxxxxxxxxx
pt satwindu utama
 
MALURI KISHORE-.pptxdsrhbcdsfvvghhhggggfff
sakthick46
 
Landscape assignment for landscape architecture
aditikoshley2
 
Top 10 UI/UX Design Agencies in Dubai Shaping Digital Experiences
Tenet UI UX
 
原版定制TUBS毕业证(布伦瑞克工业大学毕业证书)成绩单修改定制学历成绩单
jicaaeb0
 
503ea471-f798-4324-90e8-275bdab41942.pptx
a0999574
 

The Future of CSS Layout

  • 1. The Future of CSS Layout October 22, 2012 by Zoe Mickley Gillenwater Future of Web Design @zomigi zomigi.com
  • 2. What I do Books Web Stunning CSS3: Accessibility A Project-based Guide to specialist at AT&T the Latest in CSS Visual designer www.stunningcss3.com CSS developer and consultant Flexible Web Design: Creating Liquid and Elastic Layouts with CSS www.flexiblewebbook.com 2
  • 4. Problems with table layout • Complicated/bulky markup • Accessibility problems • Slower browser rendering • Rigid designs • Spacer gifs 4
  • 5. the present float layout 5
  • 6. Advantages of floats in layout • Less HTML than tables • More flexibility to change layout than tables • Can change visual order to not match HTML (somewhat) • Other content aware of floats' presence • Can use clear to get blocks out of the way 6
  • 7. Problems with float layout • Visual location tied to HTML order (somewhat) • Wrapping/float drop • Difficulty with containment • Difficulty with equal-height columns • No float:center 7
  • 8. ? what are the alternatives 8
  • 9. Alternative: display inline-block      * * only partial support in IE 7 and 6 9
  • 10. I wish my parents would stop treating me like I’m inline. Can’t they see I’m a block now? 10
  • 11. Use: centered nav bar nav ul { margin: 0; padding: 0; border-bottom: 3px solid #fff; list-style: none; text-align: center; } nav li { display: inline-block; vertical-align: bottom; margin: 0 .2em; padding: .3em .5em; ... } 11
  • 12. Use: centered nav bar • List horizontally centered • Links aligned on bottom • Links have top and bottom padding • Links can be different heights • List contains links (see its bottom border) 12
  • 13. Alternative: display table-cell      * * only in IE 8 and later 13
  • 14. How table display works • Makes boxes act like table equivalents • Example: boxes with display:table-cell act like <td> and sit on same line • Good for grid-like layouts • Disadvantage: tied to HTML order 14
  • 15. Use: hybrid fixed-fluid layout section { display: table; table-layout: fixed; width: 100%; } article { display: table-cell; padding: 10px; vertical-align: top; } article.fixed { width:250px; } 15
  • 17. the future a whole bunch of CSS3 17
  • 18. CSS3 “content-flow” modules • Multi-column Layout: flow a box’s content into multiple columns in that box • Regions: flow content into multiple, separate boxes • Exclusions and Shapes: make content flow around and within areas in more intricate ways than floating 18
  • 20. How grid template works Define invisible grid of rows and columns and specify which pieces of content go into which “slot” body { grid: "a a a a" a "b c c d" }  b c d nav { flow: a } #main { flow: c } aside { flow: d } #news { flow: b } 20
  • 21. How grid template works Define invisible grid of rows and columns and specify which pieces of content go into which “slot” body { grid: "c d" c d "b b" "a a"  } b nav { flow: a } #main { flow: c } aside { flow: d } #news { flow: b } a 21
  • 22. How grid template works Use ::slot to style slots with: • overflow • background properties • margin properties • column properties • padding properties • vertical-align • border properties • writing-mode • box-shadow • direction • box-decoration-break For example: body::slot(c) { background: #7FD13B; vertical-align: top; } 22
  • 23. Flexible Box Layout www.w3.org/TR/css3-flexbox/ 21 X 12.1 X X † * * † with -webkit- prefix can be switched on in version 18 nightlies 23
  • 24. How flexbox works • Make boxes automatically grow to fill space or shrink to avoid overflow • Give boxes proportional measurements • Lay out boxes in any direction • Align boxes on any side • Place boxes out of order from HTML 24
  • 26. Original CSS .feature { float: left; width: 30%; margin: 0 4.5% 0 0; padding: 130px 0 0 0; } 26
  • 27. Create a flex container <div id="features-wrapper"> <div class="feature" id="feature-candy"> ...</div> <div class="feature" id="feature-pastry"> ...</div> <div class="feature" id="feature-dessert"> ...</div> </div> Make sure to add the #features-wrapper { -moz, -ms, and -webkit prefixed values and display: flex; properties in real life! } 27
  • 28. Specify direction of flex items #features-wrapper { display: flex; flex-direction: row; default value } Could switch to vertical stacking in mobile/narrow-screen media query: #features-wrapper { display: flex; flex-direction: column; } 28
  • 29. Make flex items flexible .feature { flex: 1 1 0px; margin-right: 40px; padding: 130px 0 0 0; } 29
  • 30. Make flex items flexible .feature { flex: 1 1 0px; margin-right: 40px; flex basis padding: 130px 0 0 0; } flex shrink factor Same as: flex grow factor .feature { flex: 1; margin-right: 40px; padding: 130px 0 0 0; } 30
  • 31. Add a fourth feature box <div id="features-wrapper"> <div class="feature" id="feature-candy"> ...</div> <div class="feature" id="feature-pastry"> ...</div> <div class="feature" id="feature-dessert"> ...</div> <div class="feature" id="feature-bread"> ...</div> </div> 31
  • 32. All boxes adjust in width 32
  • 33. Don’t need to do this anymore .2up .feature { width: 45%; ... } .3up .feature { width: 30%; ... } .4up .feature { width: 22%; ... } 33
  • 34. Highlight a sale category .sale { padding: 130px 20px 20px 20px; border-radius: 3px; background-color: hsla(0,0%,100%,.4); } What percentage width would I set to make this twice as wide as other boxes, if I weren’t using flex? 34
  • 35. Make sale box twice as wide .sale { flex: 2; padding: 130px 20px 20px 20px; border-radius: 3px; background-color: hsla(0,0%,100%,.4); } 35
  • 36. Default equal-height columns! #features-wrapper { display: flex; align-items: stretch; } This is the default value, so we don’t need to actually set this property, but this shows you what it looks like. 36
  • 37. Vertical centering with ease! #features-wrapper { display: flex; align-items: center; } 37
  • 38. Visual order = HTML order 38
  • 39. Move sale box to front of line .sale { order: -1; flex: 2; padding: 130px 20px 20px 20px; border-radius: 3px; background-color: hsla(0,0%,100%,.4); } Default order value is 0 for all flex items, so -1 moves this one before others 39
  • 40. New visual order, same HTML 40
  • 41. Accessibility implications • Pro: keep content in logical order in HTML instead of structuring HTML to achieve visual layout • Con: focus/tab order won’t always match expected order, may jump around seemingly randomly 41
  • 42. Columns are too narrow 42
  • 43. Create multi-line flex container #features-wrapper { display: flex; flex-wrap: wrap; Allow children flex items to wrap to multiple lines } .sale { order: -1; Make box fill line flex: 1 1 100%; Remove gap to right, margin: 0 0 20px 0; add space below padding: 130px 20px 20px 20px; border-radius: 3px; background-color: hsla(0,0%,100%,.4); } 43
  • 44. Flex items can now wrap 44
  • 45. Change icon position .sale { order: -1; flex: 1 1 100%; margin: 0 0 20px 0; padding: 20px 20px 1px 170px; border-radius: 3px; background-color: hsla(0,0%,100%,.4); background-position: 20px 0; } 45
  • 47. use flexbox now for progressive enhancement  47
  • 48. How can I make this form: • Display on a single line with image • Vertically centered with image • Span full-width of container 48
  • 49. Inline-block achieves: Display on a single line with image Vertically centered with image X Span full-width of container 49
  • 50. Different units make life hard Pixels Ems Some mystery percentage 50
  • 51. Make the text input flex #order, #order form { Make outer div and form display: flex; into flex containers align-items: center; } Vertically center kiddos #order form { Make form take up all flex: 1; } space next to image #order #message { Make text input take up flex: 1; all space in form left min-width: 7em; after label and button margin: 0 5px; } But don’t let it get crazy- small 51
  • 52. Use inline-block with flexbox 52
  • 53. Use inline-block with flexbox #order img, #order form { display: inline-block; vertical-align: middle; } #order, #order form { display: flex; align-items: center; } #order form { flex: 1; } #order #message { flex: 1; min-width: 7em; margin: 0 5px; } 53
  • 54. Full-width nav bar nav ul { nav li { display: table; display: table-cell; width: 100%; text-align: center; } margin: 0; padding: 0; list-style: none; } 54
  • 55. Not so hot with no backgrounds Uneven spacing Don’t like these gaps 55
  • 56. Even spacing with flexbox nav ul { display: flex; justify-content: space-between; margin: 0; padding: 0; list-style: none; } 56
  • 57. Use inline-block with flexbox 57
  • 58. Use inline-block with flexbox nav ul { display: flex; justify-content: space-between; margin: 0; padding: 0; list-style: none; text-align: center; } nav li { display: inline-block; } 58
  • 59. Or use Modernizr script http://modernizr.com nav ul { nav li { display: table; display: table-cell; width: 100%; } margin: 0; .flexbox nav li { padding: 0; display: list-item; list-style: none; } } .flexbox nav ul { display: flex; } 59
  • 61. Learn more Download slides and get links at http://zomigi.com/blog/future-css-layout-fowd Zoe Mickley Gillenwater @zomigi [email protected] zomigi.com | stunningcss3.com | flexiblewebbook.com Title photo by Gilderic Photography (http://www.flickr.com/photos/gilderic/6885830288/) Rocket designed by Jason Peters from The Noun Project 61