SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Flexbox
(Flexible Box Layout)
The CSS3 Flexible Box, or flexbox, is a
layout mode providing for the arrangement
of elements on a page such that the
elements behave predictably when the page
layout must accommodate different screen
sizes and different display devices.
Mozilla Developer Network
What is Flexbox?
Designed to provide a better way to lay out, align, and
distribute space among items in a container - even when
dynamic.
Flexbox is a CSS layout mode designed to ensure that
elements behave predictably in different screen sizes and
devices. … it creates Intelligent boxes.
Easily Defined in CSS and markup (incl. media queries).
Directionally agnostic. (block = vertically-based & inline
= horizontally-based)
Best used for smaller modules over broader layout
“Old” and “New” syntax
Oddly, the syntax has changed since initial conception -
which has resulted in common references to “old” and “new”
versions.
Weaving together the two, (and in-betweens) provides decent
browser support - especially for order-controlled grids
▪ Chris Coyier (2013)
Requires additional code and prefixed code when authoring
for best results. … consider a js library (autoprefixer)
Examples
NEW: display: flex;
TWEEN: display; -ms-flexbox;
OLD: display: box;
Core Concepts
Flexbox consists of:
▪Flex Containers
▪Flex Items
Flex Container
Declared on an element using the display property
display: flex or display: inline-flex
Flex Item
Flex items are positioned inside of a flex container along
a “flex line”. By default 1 flex line per flex container.
contaner
< items
Core Concepts
Flex Line (axis, rope)
Flex items are laid out in a single “line” (default) or on
several “lines” according to the flex-wrap property. No
longer think about top-to-bottom or left-to-right. Abandon
rows/columns thinking.
direction orientation
Core Concepts
Flex Line
In addition to Alignment, Orientation and Direction, flex
lines can be reordered! This is huge. We can now
structure our HTML for semantics, accessibility, and SEO
.item { order: <integer>; }
order
By default, flex
items are laid
out in source
order
Core Concepts
Nested Flex Lines
Each flexbox layout (box) can contain another set that is
on their own line.
Nested flexboxes
Core Concepts
flex-wrap
By default all flex items will try to fit together into one
line. This can be changed and direction can be modified
using the flex-wrap property.
.container {
flex-wrap: wrap; nowrap | wrap | wrap reverse
}
Core Concepts
flex-grow
Defines the ability for a flex item to grow if needed.
(unitless values serve as proportion) An item set at 2
would be twice as big as an item set at 1.
.item {
flex-grow: <number>; /* default = 0 */
}
flex-shrink
Defines the ability for a flex item to shrink if needed.
.item {
flex-shrink: <number>; /* default = 0 */
}
Core Concepts
flex-basis
Defines the default size of an element - before remaining
space is distributed. Length or keyword values.
.item {
flex-basis: <number>;
}
If set to 0, the extra space around it is not factored in.
If set to auto (keyword), the extra space is distributed by
its flex-grow value
Core Concepts
flex (shortcut)
Combines flex-grow, flex-shrink (opt) and flex-basis (opt).
Default = 0 1 auto
RECOMMENDED over individual properties.
.item {
flex: 1 0 0;
}
1
Let’s look at some Code
To the text-editor!
Some other examples (that I didn’t have time to build)
▪ https://dl.dropboxusercontent.com/u/444684/flexbox/flexbox1.html
▪ https://dl.dropboxusercontent.com/u/444684/flexbox/flexbox2.html
▪ https://dl.dropboxusercontent.com/u/444684/flexbox/flexbox3.html
Browser Adoption
Can I Use? - caniuse.com
Flexbox is the current new and now way of
thinking about CSS layout - but not the end.
Historic and current layout practices
▪ Table based layouts
▪ Float based layouts (CSS1)
▪ Positioning (CSS2)
▪ Flexbox “This is real layout. It’s not a hack” - Jeremy Keith
▫ Flexbox (old)
▫ Flexbox (mid/transitional)
▫ Flexbox (standard/final)
The future is coming ‘soon’ and will likely build upon the
flexbox model and techniques.
▪ Grid Layout (ie10 has adopted an early specification)
▪ Regions and Exclusions (Adobe initiative)
● https://developer.mozilla.org/en-
US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes
● http://www.sitepoint.com/are-we-ready-to-use-flexbox/
● https://css-tricks.com/using-flexbox/
● http://caniuse.com/#feat=flexbox
● https://css-tricks.com/snippets/css/a-guide-to-flexbox/
● https://www.smashingmagazine.com/2013/05/centering-elements-with-flexbox/
● https://www.smashingmagazine.com/2015/08/flexible-future-for-web-design-with-flexbox/
References

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Introducing CSS Grid
Introducing CSS GridIntroducing CSS Grid
Introducing CSS Grid
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
 
CSS3 Flex Layout
CSS3 Flex LayoutCSS3 Flex Layout
CSS3 Flex Layout
 
CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
 
Css floats
Css floatsCss floats
Css floats
 
Css Display Property
Css Display PropertyCss Display Property
Css Display Property
 
CSS
CSSCSS
CSS
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
CSS Grid
CSS GridCSS Grid
CSS Grid
 
Css
CssCss
Css
 
Css pseudo-classes
Css pseudo-classesCss pseudo-classes
Css pseudo-classes
 
CSS
CSSCSS
CSS
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
Html & Css presentation
Html  & Css presentation Html  & Css presentation
Html & Css presentation
 
Introduction to CSS Grid Layout
Introduction to CSS Grid LayoutIntroduction to CSS Grid Layout
Introduction to CSS Grid Layout
 
CSS Positioning Elements.pdf
CSS Positioning Elements.pdfCSS Positioning Elements.pdf
CSS Positioning Elements.pdf
 
Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, css
 
Bootstrap grids
Bootstrap gridsBootstrap grids
Bootstrap grids
 

Ähnlich wie CSS Flexbox (flexible box layout)

Flexbox Will Shock You!
Flexbox Will Shock You!Flexbox Will Shock You!
Flexbox Will Shock You!Scott Vandehey
 
Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?jameswillweb
 
Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Zoe Gillenwater
 
Is Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconfIs Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconfjameswillweb
 
Show & tell - Flex in flux
Show & tell - Flex in fluxShow & tell - Flex in flux
Show & tell - Flex in fluxDan Dineen
 
CSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive DesignCSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive DesignArash Milani
 
Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Zoe Gillenwater
 
#4 HTML & CSS [know-how]
#4 HTML & CSS [know-how]#4 HTML & CSS [know-how]
#4 HTML & CSS [know-how]Dalibor Gogic
 
Understanding the flex layout
Understanding the flex layoutUnderstanding the flex layout
Understanding the flex layoutBarak Drechsler
 
Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Zoe Gillenwater
 
Putting Flexbox into Practice
Putting Flexbox into PracticePutting Flexbox into Practice
Putting Flexbox into PracticeZoe Gillenwater
 
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBoxKobkrit Viriyayudhakorn
 
Intro to Flexbox with Real Word Examples
Intro to Flexbox with Real Word ExamplesIntro to Flexbox with Real Word Examples
Intro to Flexbox with Real Word ExamplesJennifer Bland
 
Understanding flexbox
Understanding flexboxUnderstanding flexbox
Understanding flexboxmustafa sarac
 
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...Jalal Mostafa
 
CSS Conf Budapest - New CSS Layout
CSS Conf Budapest - New CSS LayoutCSS Conf Budapest - New CSS Layout
CSS Conf Budapest - New CSS LayoutRachel Andrew
 

Ähnlich wie CSS Flexbox (flexible box layout) (20)

Flexbox Will Shock You!
Flexbox Will Shock You!Flexbox Will Shock You!
Flexbox Will Shock You!
 
Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?Is Flexbox the Future of Layout?
Is Flexbox the Future of Layout?
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)
 
A complete guide to flexbox
A complete guide to flexboxA complete guide to flexbox
A complete guide to flexbox
 
Flex Web Development.pdf
Flex Web Development.pdfFlex Web Development.pdf
Flex Web Development.pdf
 
Is Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconfIs Flexbox the Future of Layout -bdconf
Is Flexbox the Future of Layout -bdconf
 
Show & tell - Flex in flux
Show & tell - Flex in fluxShow & tell - Flex in flux
Show & tell - Flex in flux
 
CSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive DesignCSS3 Flexbox & Responsive Design
CSS3 Flexbox & Responsive Design
 
Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)
 
#4 HTML & CSS [know-how]
#4 HTML & CSS [know-how]#4 HTML & CSS [know-how]
#4 HTML & CSS [know-how]
 
Understanding the flex layout
Understanding the flex layoutUnderstanding the flex layout
Understanding the flex layout
 
Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)
 
Putting Flexbox into Practice
Putting Flexbox into PracticePutting Flexbox into Practice
Putting Flexbox into Practice
 
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
 
Intro to Flexbox with Real Word Examples
Intro to Flexbox with Real Word ExamplesIntro to Flexbox with Real Word Examples
Intro to Flexbox with Real Word Examples
 
Understanding flexbox
Understanding flexboxUnderstanding flexbox
Understanding flexbox
 
Layout with flexbox
Layout with flexboxLayout with flexbox
Layout with flexbox
 
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
 
CSS Conf Budapest - New CSS Layout
CSS Conf Budapest - New CSS LayoutCSS Conf Budapest - New CSS Layout
CSS Conf Budapest - New CSS Layout
 

Kürzlich hochgeladen

%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 

Kürzlich hochgeladen (20)

%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

CSS Flexbox (flexible box layout)

  • 2. The CSS3 Flexible Box, or flexbox, is a layout mode providing for the arrangement of elements on a page such that the elements behave predictably when the page layout must accommodate different screen sizes and different display devices. Mozilla Developer Network
  • 3. What is Flexbox? Designed to provide a better way to lay out, align, and distribute space among items in a container - even when dynamic. Flexbox is a CSS layout mode designed to ensure that elements behave predictably in different screen sizes and devices. … it creates Intelligent boxes. Easily Defined in CSS and markup (incl. media queries). Directionally agnostic. (block = vertically-based & inline = horizontally-based) Best used for smaller modules over broader layout
  • 4. “Old” and “New” syntax Oddly, the syntax has changed since initial conception - which has resulted in common references to “old” and “new” versions. Weaving together the two, (and in-betweens) provides decent browser support - especially for order-controlled grids ▪ Chris Coyier (2013) Requires additional code and prefixed code when authoring for best results. … consider a js library (autoprefixer) Examples NEW: display: flex; TWEEN: display; -ms-flexbox; OLD: display: box;
  • 5. Core Concepts Flexbox consists of: ▪Flex Containers ▪Flex Items Flex Container Declared on an element using the display property display: flex or display: inline-flex Flex Item Flex items are positioned inside of a flex container along a “flex line”. By default 1 flex line per flex container. contaner < items
  • 6. Core Concepts Flex Line (axis, rope) Flex items are laid out in a single “line” (default) or on several “lines” according to the flex-wrap property. No longer think about top-to-bottom or left-to-right. Abandon rows/columns thinking. direction orientation
  • 7. Core Concepts Flex Line In addition to Alignment, Orientation and Direction, flex lines can be reordered! This is huge. We can now structure our HTML for semantics, accessibility, and SEO .item { order: <integer>; } order By default, flex items are laid out in source order
  • 8. Core Concepts Nested Flex Lines Each flexbox layout (box) can contain another set that is on their own line. Nested flexboxes
  • 9. Core Concepts flex-wrap By default all flex items will try to fit together into one line. This can be changed and direction can be modified using the flex-wrap property. .container { flex-wrap: wrap; nowrap | wrap | wrap reverse }
  • 10. Core Concepts flex-grow Defines the ability for a flex item to grow if needed. (unitless values serve as proportion) An item set at 2 would be twice as big as an item set at 1. .item { flex-grow: <number>; /* default = 0 */ } flex-shrink Defines the ability for a flex item to shrink if needed. .item { flex-shrink: <number>; /* default = 0 */ }
  • 11. Core Concepts flex-basis Defines the default size of an element - before remaining space is distributed. Length or keyword values. .item { flex-basis: <number>; } If set to 0, the extra space around it is not factored in. If set to auto (keyword), the extra space is distributed by its flex-grow value
  • 12. Core Concepts flex (shortcut) Combines flex-grow, flex-shrink (opt) and flex-basis (opt). Default = 0 1 auto RECOMMENDED over individual properties. .item { flex: 1 0 0; }
  • 13. 1 Let’s look at some Code To the text-editor!
  • 14. Some other examples (that I didn’t have time to build) ▪ https://dl.dropboxusercontent.com/u/444684/flexbox/flexbox1.html ▪ https://dl.dropboxusercontent.com/u/444684/flexbox/flexbox2.html ▪ https://dl.dropboxusercontent.com/u/444684/flexbox/flexbox3.html
  • 15. Browser Adoption Can I Use? - caniuse.com
  • 16. Flexbox is the current new and now way of thinking about CSS layout - but not the end. Historic and current layout practices ▪ Table based layouts ▪ Float based layouts (CSS1) ▪ Positioning (CSS2) ▪ Flexbox “This is real layout. It’s not a hack” - Jeremy Keith ▫ Flexbox (old) ▫ Flexbox (mid/transitional) ▫ Flexbox (standard/final) The future is coming ‘soon’ and will likely build upon the flexbox model and techniques. ▪ Grid Layout (ie10 has adopted an early specification) ▪ Regions and Exclusions (Adobe initiative)
  • 17. ● https://developer.mozilla.org/en- US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes ● http://www.sitepoint.com/are-we-ready-to-use-flexbox/ ● https://css-tricks.com/using-flexbox/ ● http://caniuse.com/#feat=flexbox ● https://css-tricks.com/snippets/css/a-guide-to-flexbox/ ● https://www.smashingmagazine.com/2013/05/centering-elements-with-flexbox/ ● https://www.smashingmagazine.com/2015/08/flexible-future-for-web-design-with-flexbox/ References