css3 flex layout

29
CSS3 Flexbox BY - Neha Sharma ([email protected] ) Follow @ https://twitter.com/nehadesigner Flexible Layout

Upload: neha-sharma

Post on 15-Apr-2017

444 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: CSS3 Flex Layout

CSS3 Flexbox

BY - Neha Sharma ([email protected]) Follow @ https://twitter.com/nehadesigner

Flexible Layout

Page 2: CSS3 Flex Layout

AGENDAPart One – Introduction• What is Flex• Why we need Flex

Part Two – Syntax• Flex• Order• align-items• Justify-content• Flex-wrap• Flex-grow• Flex-shrink

Part Three – Examples

Page 3: CSS3 Flex Layout

We love FloatsIt’s a question not a statement.

Page 4: CSS3 Flex Layout

Floats and Issues• Weird behaving• Clearfix• Cross- browser issues• Parent container breaking• Content spill over

Page 5: CSS3 Flex Layout

What you want to change?Flexible parent container, No floats Hack, no clear fix, adjustable child container,

Page 6: CSS3 Flex Layout

Why Flexbox?

Page 7: CSS3 Flex Layout

What is Flex?• Flexbox or Flexible box is the css3 property • Flexbox is the layout mode• Improvement over the Floats• It helps in displaying the elements on the page as per

the device size and screen size , available space• It helps in achieving the grid layout

Page 8: CSS3 Flex Layout

What is Flex?“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.This is the improvement of using floats for achieving the Grid layout and margin/content overlapping issues.”

- Mozilla Development Network

Page 9: CSS3 Flex Layout

Let’s Meet the Flex

Page 10: CSS3 Flex Layout

Flex Vocabulary

Page 11: CSS3 Flex Layout

FlexTo make the any container behave like Flexible layout . You have to declare it flex. By default flex is block level element.

display : <flex | flex-inline>

Page 12: CSS3 Flex Layout

Flex ItemsElements within in the flex containers are the flex items.

They can be arranged across the main or cross axis

Page 13: CSS3 Flex Layout

Flex AxisEvery flex model have 2 axes - Main and Cross . Main axis is the horizontal axis and the cross axis is the axis perpendicular to the main.

There are 3 properties with the axis:- Justify-content- Align-items- Align-self

Page 14: CSS3 Flex Layout

Justify-contentHow the browser distributes space between and around flex items along the main-axis of their container.

Justify-content : <flex-start | flex-end | center | space-around | space-between>

Page 15: CSS3 Flex Layout

align-itemsAlign the current flex items just like the justify-content but across the cross axis.

Align-items : <flex-start | flex-end | center | baseline | stretch >

Page 16: CSS3 Flex Layout

align-selfIt will override the current flex items and align itself across the cross axis

Align-items : <flex-start | flex-end | center | baseline | stretch >

Page 17: CSS3 Flex Layout

flex-directionFlex direction defines the flow of the flex items across the main/cross axis.

Flex-direction: <row | column | row-reverse | column-reverse>

Page 18: CSS3 Flex Layout

orderDefines the way flex-items will display on the web-page. By default they come as define on the page.

Order takes the integer value .Negatives are not allowed and in ascending order they will come on the page

order: <integer>

Page 19: CSS3 Flex Layout

order

Page 20: CSS3 Flex Layout

Flex LinesFlex-items can be appear single line or multiple line along the cross axis .

Page 21: CSS3 Flex Layout

Flex WrapFlex-wrap property controls how the flex-items will stacked or not stacked

flex-wrap <wrap | no-wrap>

Page 22: CSS3 Flex Layout

Flex DimensionsFlex-items can be appear single line or multiple line along the cross axis. Flex-wrap property controls how the flex-items will stacked or not stacked

There are 3 properties:- flex-basis- flex-grow- flex-shrink

Page 23: CSS3 Flex Layout

Flex BasisIt defines the initial flex basis which is the initial size of the flex item

Flex-basis : <width | auto >

Page 24: CSS3 Flex Layout

Flex GrowIt defines the initial value of the flex item to grow

Flex-grow : <integer | 0 >

Page 25: CSS3 Flex Layout

Flex ShrinkIt defines the initial value of the flex item to shrink

Flex-shrink : <integer | 1>

Page 26: CSS3 Flex Layout

ExampleA webpage without Floats http://kodshare.com/codes/66rLBNZBsL

A navigation with flexhttp://kodshare.com/codes/8DGEAcRvg3

Page 27: CSS3 Flex Layout

Browser SupportIE 10 with prefixes

Chrome 21 with prefixes

Safari 6.1 with prefixes

Firefox 20 +

Page 28: CSS3 Flex Layout

Questions and Feedbacks

Page 29: CSS3 Flex Layout

Referenceso https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxeso http://www.w3schools.com/cssref/css3_pr_flex.asp