SlideShare a Scribd company logo
Understanding the
Flex Layout
By Barak Drechsler
Flex Box Model
A module of CSS that defines a CSS box model optimized for user interface design. In the flex
layout model, the children of a flex container can be laid out in any direction, and can “flex” their
sizes, either growing to fill unused space or shrinking to avoid overflowing the parent.
Both horizontal and vertical alignment of the children can be easily manipulated. Nesting of
these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts
in two dimensions.
CSS Flexible Box Layout
1.ability to alter its items' width and/or height to best fit in the available space on any display
device.
2.flexbox layout algorithm is direction-agnostic as opposed to the block layout, which is
vertically-biased, or the inline layout, which is horizontally-biased
3.Flexbox layout is most appropriate for the components of an application, and small-scale
layouts, while the (emerging) Grid layout is intended for larger scale layouts.
Flex Layout agenda
1. Flex Container, the parent element, that defines the flex behaviour, defined by display: flex
or flex-inline.
2. Flex Item, any child of a Flex container becomes, a flex item.
3. Axes:
a. The flex-direction property establishes the main axis.
b. The justify-content property defines how flex items are laid out along the main axis on the current
line.
The Basics (MDN)
4. order , allows to adjust flex items order.
5.Flex-wrap, flex can be defined either single line or multiline.
6. The flex property shorthands the flex-grow, flex-shrink, and flex-basis properties to establish
the flexibility of the flex items.
The Basics
Understanding the flex layout
1. The flex-basis specifies initial main size of a flex item. (the size to be defined before any
other factors apply).
2. The flex-grow - specifies the grow factor of each element, if any space remaining.
3. The flex-shrink - specifies the shrink factor, if there isn’t enough space for all elements to
fit.
4. You should use the flex shorthand as best practice.
a. One value - flex-grow flex: 1;
Flex-basis, flex-grow & flex-shrink
At first the browser calculate each item size, then it check the amount of remaining space.
If extra space available each item will receive its flex grow portion, if there isn’t enough space
each item will shrink by its flex shrink portion.
1. Calculate the Remaining Space: Container main size - ( sum of size of flex items baisias)
2. If Remaining Space is positive, apply growth factor.
3. If it negative apply shrink factor.
4. Growth: basis size + (remaining space * (flex-grow/ total flexs ))
Flex Calculation
Play Time - Flex
Flex Playground
Flex Calculator
Flex have a wide browser support in newer browsers
Although it not perfect: see Github Known Flex Bugs - most are IE 10-11 related, but not only.
Browser Support
https://philipwalton.github.io/solved-by-flexbox/
Dynamic Height Overflows
Solved By Flex
1. In firefox or old chromes, in order for overflow auto to work each flex item must have min-
height 0, or min-width: 0 (depends on scrolling direction)
2. Because of some issues with Safari, do not use height 100% of flex: 1 items, keep nesting
flex: 1 if needed.
Browser Compatibility Gotchas
1. We use angular material design, use its grid system.
https://material.angularjs.org/latest/layout/introduction
Our day to day
Questions?

More Related Content

PPTX
Js: master prototypes
PPTX
Javascript: master this
PDF
The Box Model
PPTX
Floating
PDF
Intro to OOCSS Workshop
PDF
CSS3 filterとtransformをtransition, animationでアニメーション
ODP
Cascading Style Sheets - Part 02
PDF
Dynamic CSS: Transforms, Transitions, and Animation Basics
Js: master prototypes
Javascript: master this
The Box Model
Floating
Intro to OOCSS Workshop
CSS3 filterとtransformをtransition, animationでアニメーション
Cascading Style Sheets - Part 02
Dynamic CSS: Transforms, Transitions, and Animation Basics

Viewers also liked (11)

PPTX
Css floats
PDF
Css positioning
PPTX
Css animation
PPTX
CSS Transitions, Transforms, Animations
PDF
CSS Layouting #4 : Float
PDF
Efficient, maintainable CSS
PDF
CSS Layouting #5 : Position
PDF
CSS Box Model
PDF
Css box model
PDF
CSS Layouting #3 : Box Model
PPTX
Box model
Css floats
Css positioning
Css animation
CSS Transitions, Transforms, Animations
CSS Layouting #4 : Float
Efficient, maintainable CSS
CSS Layouting #5 : Position
CSS Box Model
Css box model
CSS Layouting #3 : Box Model
Box model
Ad

Similar to Understanding the flex layout (20)

PPTX
CSS Flexbox (flexible box layout)
PDF
Show & tell - Flex in flux
PDF
Flexbox Will Shock You!
PPTX
CSS3 Flex Layout
PDF
Putting Flexbox into Practice (Fronteers)
PDF
Is Flexbox the Future of Layout?
PDF
Leveling Up with Flexbox (Smashing Conference)
PDF
Putting Flexbox into Practice
PDF
A complete guide to flexbox
PDF
Is Flexbox the Future of Layout -bdconf
PPTX
Flex box
PDF
World of Flexbox
PDF
Intro to Flexbox with Real Word Examples
PPTX
flexbox report
PDF
Introduction to css flexbox
PDF
Flexboxsheet
PDF
Understanding flexbox
PPTX
Flexbox
PDF
Leveling Up With Flexbox (Smart Web Conference)
PDF
Flexbox: One Giant Leap for Web Layout (Breaking Development 2013)
CSS Flexbox (flexible box layout)
Show & tell - Flex in flux
Flexbox Will Shock You!
CSS3 Flex Layout
Putting Flexbox into Practice (Fronteers)
Is Flexbox the Future of Layout?
Leveling Up with Flexbox (Smashing Conference)
Putting Flexbox into Practice
A complete guide to flexbox
Is Flexbox the Future of Layout -bdconf
Flex box
World of Flexbox
Intro to Flexbox with Real Word Examples
flexbox report
Introduction to css flexbox
Flexboxsheet
Understanding flexbox
Flexbox
Leveling Up With Flexbox (Smart Web Conference)
Flexbox: One Giant Leap for Web Layout (Breaking Development 2013)
Ad

More from Barak Drechsler (6)

PPTX
Stay lazy, use lerna
PPTX
Atomic javascript
PPTX
Room service (worker) please!
PPTX
From MVC to Component Based Architecture
PPTX
Fundamentals of Browser Rendering Css Overview PT 2
PPTX
Fundamentals of Browser Rendering Css Overview PT 1
Stay lazy, use lerna
Atomic javascript
Room service (worker) please!
From MVC to Component Based Architecture
Fundamentals of Browser Rendering Css Overview PT 2
Fundamentals of Browser Rendering Css Overview PT 1

Recently uploaded (20)

PPT
Ethics in Information System - Management Information System
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
Introduction to cybersecurity and digital nettiquette
PPTX
Funds Management Learning Material for Beg
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
PDF
Exploring VPS Hosting Trends for SMBs in 2025
DOC
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
PPTX
artificial intelligence overview of it and more
PPTX
Internet___Basics___Styled_ presentation
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
The Ikigai Template _ Recalibrate How You Spend Your Time.pdf
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
t_and_OpenAI_Combined_two_pressentations
PPTX
E -tech empowerment technologies PowerPoint
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPT
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
Ethics in Information System - Management Information System
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Introduction to cybersecurity and digital nettiquette
Funds Management Learning Material for Beg
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Unit-1 introduction to cyber security discuss about how to secure a system
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
Exploring VPS Hosting Trends for SMBs in 2025
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
artificial intelligence overview of it and more
Internet___Basics___Styled_ presentation
Design_with_Watersergyerge45hrbgre4top (1).ppt
The Ikigai Template _ Recalibrate How You Spend Your Time.pdf
Module 1 - Cyber Law and Ethics 101.pptx
t_and_OpenAI_Combined_two_pressentations
E -tech empowerment technologies PowerPoint
SASE Traffic Flow - ZTNA Connector-1.pdf
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt

Understanding the flex layout

  • 3. A module of CSS that defines a CSS box model optimized for user interface design. In the flex layout model, the children of a flex container can be laid out in any direction, and can “flex” their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated. Nesting of these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts in two dimensions. CSS Flexible Box Layout
  • 4. 1.ability to alter its items' width and/or height to best fit in the available space on any display device. 2.flexbox layout algorithm is direction-agnostic as opposed to the block layout, which is vertically-biased, or the inline layout, which is horizontally-biased 3.Flexbox layout is most appropriate for the components of an application, and small-scale layouts, while the (emerging) Grid layout is intended for larger scale layouts. Flex Layout agenda
  • 5. 1. Flex Container, the parent element, that defines the flex behaviour, defined by display: flex or flex-inline. 2. Flex Item, any child of a Flex container becomes, a flex item. 3. Axes: a. The flex-direction property establishes the main axis. b. The justify-content property defines how flex items are laid out along the main axis on the current line. The Basics (MDN)
  • 6. 4. order , allows to adjust flex items order. 5.Flex-wrap, flex can be defined either single line or multiline. 6. The flex property shorthands the flex-grow, flex-shrink, and flex-basis properties to establish the flexibility of the flex items. The Basics
  • 8. 1. The flex-basis specifies initial main size of a flex item. (the size to be defined before any other factors apply). 2. The flex-grow - specifies the grow factor of each element, if any space remaining. 3. The flex-shrink - specifies the shrink factor, if there isn’t enough space for all elements to fit. 4. You should use the flex shorthand as best practice. a. One value - flex-grow flex: 1; Flex-basis, flex-grow & flex-shrink
  • 9. At first the browser calculate each item size, then it check the amount of remaining space. If extra space available each item will receive its flex grow portion, if there isn’t enough space each item will shrink by its flex shrink portion. 1. Calculate the Remaining Space: Container main size - ( sum of size of flex items baisias) 2. If Remaining Space is positive, apply growth factor. 3. If it negative apply shrink factor. 4. Growth: basis size + (remaining space * (flex-grow/ total flexs )) Flex Calculation
  • 10. Play Time - Flex Flex Playground Flex Calculator
  • 11. Flex have a wide browser support in newer browsers Although it not perfect: see Github Known Flex Bugs - most are IE 10-11 related, but not only. Browser Support
  • 13. 1. In firefox or old chromes, in order for overflow auto to work each flex item must have min- height 0, or min-width: 0 (depends on scrolling direction) 2. Because of some issues with Safari, do not use height 100% of flex: 1 items, keep nesting flex: 1 if needed. Browser Compatibility Gotchas
  • 14. 1. We use angular material design, use its grid system. https://material.angularjs.org/latest/layout/introduction Our day to day

Editor's Notes

  • #4: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #5: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #6: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes
  • #7: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes
  • #8: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes
  • #9: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes
  • #10: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes