CSS Flexbox model

Flexbox
----------

Complex things like flexible grid layouts are so hard using tables, floats, inline-blocks.

Flexbox consists of Flex containers and flex items.

Flex container: display property set as flex or inline-flex.

Flex Item: Every child of flex container.

Everything outside a Flex Container and inside a Flex Item is rendered as usual. In short, Flexbox defines how Flex Items are laid out inside of Flex Containers.

Flex Lines

Flex Items are positioned inside a Flex Container along a Flex Line. By default there is only one Flex Line per Flex Container.

The Main Axis and the Cross Axis

To abstract over the writing-mode, Flexbox uses the concepts of the Main Axis and the Cross Axis. Flex Lines follow the Main Axis. The Cross Axis is perpendicular to the Main Axis.

The names for the starting points, ending points, and directions of each axis are as follows:

Main Start
Main End
Main Direction (sometimes called the Flow Direction)
Cross Start
Cross End
Cross Direction

Flex container properties

flex-direction
--------------
Default value is row

row-reverse: The Main Start and Main End are swapped. If the writing-mode is left to right, Flex Items are now laid out right to left.
column: The Main Axis and the Cross Axis are swapped. If the writing system is horizontal, the Flex Items are now laid out vertically.
column-reverse: Same as column, but reversed.

justify-content: adjusts the positions of Flex Items on the Main Axis
---------------
flex-start (default)
flex-end
center
space-between
space-around

align-items: adjusts the way Flex Items are positioned on the Cross Axis
-----------
flex-start (default)
flex-end
center
baseline: causes Flex Items to be aligned along their baseline. Baselines are calculated based on the content of the Flex Items.
stretch

flex-wrap: Using flex-wrap you can create Flex Containers with multiple Flex Lines.
---------
nowrap (default)
wrap: Flex Items wrap onto additional Flex Lines if there is not enough room for them on one Flex Line
wrap-reverse

align-content: modifies the behavior of flex-wrap; aligns teh
-------------
stretch (default)
flex-start
flex-end
center
space-between
space-around

flex-flow: shorthand for flex-direction and flex-wrap
---------


Properties of Flex Items

order: Setting orders for Flex Items adjusts their order when rendered

This can be useful for accessibility, where the document order and the displayed order may need to be different.

margin:

align-self: overrides the Flex Container’s align-items property
----------
stretch (default)
flex-start
flex-end
center
baseline

flex: specifies how a Flex Item will be prioritized when free space is being distributed on the Main Axis.
----
flex: [number]: specifies a number that represents the ratio of free space

flex: initial: inflexible when there is free space, but can shrink smaller if needed

flex: auto : fully flexible along the Main Axis.

flex: none : fully inflexible in all situations.

flex: [flex-grow] [flex-shrink] [flex-basis]

visibility:


Reference URLs
-------------------
https://medium.freecodecamp.org/even-more-about-how-flexbox-works-explained-in-big-colorful-animated-gifs-a5a74812b053
https://bocoup.com/blog/dive-into-flexbox
https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Comments

Popular posts from this blog

Responsive Web Design

Website Accessibility Tips