- Layout model
- One-dimensional
- Either columns or rows are affected while grid can control both rows and columns simultaneously.
- Specialty
- Space distribution
- Alignment capability
- Section block text inline
- Not required but not always
- Float properties
- Position properties
- Requirements
- One parent div
- One or more child div's.
- How display:flex properties act when use in a element (div)? Means only use display:flex in an element.
- Block-level element itself (flex container).
- New browser compatibility for flexbox
- display: flex;
- The two axes of flexbox
- The main axes
- flex direction
- Child Element
- Flex items
- Flexbox requires two elements parent and child.
- Parent Element
- Flex container
- Child Element
- Flex items
- Parent div's properties | Flex container
- display: flex (required), the child items all become flex items arranged in a row.
- flex-direction: row(default) | row-reverse | column | column-reverse | initial | inherit.
- flex-wrap: nowrap(default) | wrap | wrap-reverse | initial | inherit.
- nowrap do nothing, try to set items in one line. Child item has width property then wrap property try to set items wrap if possible.
- flex-flow: Cartesian product of flex-direction and flex-wrap. So you set direction of items flex-wrap.
- row nowrap | row-reverse nowrap | column nowrap | column-reverse nowrap | row wrap | row-reverse wrap | column wrap | column-reverse wrap | row wrap-reverse | row-reverse wrap-reverse | column wrap-reverse | column-reverse wrap-reverse.
- forget about initial.
- order: number | initial | inherit.
- Child div(items) displays as per your serial order. Override sequential order user order property.
- flex: flex-grow [goes down/side and cover] | flex-shrink flex-basis | auto | initial | inherit.
- Properties that control alignment
- align-items: stretch(default) | center | flex-start | flex-end | baseline | initial | inherit.
- Where child elements itself starts (middle, top, etc.) not child's inside content.
- align-items:center; means it's vertically center. Mainly works on the cross axis.
- flex-start + baseline and flex-end starts top or bottom of a page.
- align-items browser compatibility:
- -webkit-align-items: center;
- -moz-align-items: center;
- -ms-align-items: center;
- -o-align-items: center;
- align-items: center;
- justify-content: flex-start(default)[top] | flex-end[] | center | space-between | space-around | initial | inherit.
- Like align-items flex-start and flex-end similar so actual effect depends on flex-wrap.
- Align the item on the main axis, basically horizontal.
- align-self: auto(default) [parent property if parent exist otherwise stretch] | stretch | center | flex-start | flex-end | baseline | initial | inherit.
- Only of single item individually.
- align-content: controls space between flex lines on the cross axis.
- Child properties | Flex items
- The Cross Axis | Up to Down | Column focus
- The flex items on the cross axis, align-items and align-self properties controls alignment, while down the columns if flex-direction is row and along the row if flex-direction is column.
- So, flex-direction [default: row] decides how items are grouped like a row or column. While align-items or align-self decides how they behave on a row or column.
- align-self properties sets one items, while align-items sets on all flex items as a group. Specially you sets align-self properties. [.abc .xyz { align-self: center;}]
- Align content (align-content) Sometime individual items act like content so use align-content. [.abc { display: flex; flex-wrap: wrap; height: 400px; align-content: space-between;}]
- The Main Axis | Top to Bottom | Row focus
- align-items the main axis working Top to bottom, so stretch may be merged.
- justify-content like align-items but row basis.
- Why flexbox layout mode?
- Suppose you use bootstrap frame work, but some section is totally isolated from bootstrap classes, then you prefer flexbox instead position or float for responsiveness.
- Outdated information
- display: box or display: flexbox this is outdated information.
Referance: https://developer.mozilla.org/
No comments:
Post a Comment