?> Background::point_right: flex, flex layout concept
The Flex layout is called CSS Flexible Box Layout Module. It is a new page layout solution proposed by W3C. The first version was released in 2009. Up to now, W3C has released 12 versions, latest version was launched in 20171019 and has been supported by all major browsers, so please use it boldly ~
https://www.w3.org/TR/2016/CR-css-flexbox-1-20160526/
https://www.w3.org/TR/2016/CR-css-flexbox-1-20160301/
https://www.w3.org/TR/2015/WD-css-flexbox-1-20150514/
https://www.w3.org/TR/2014/WD-css-flexbox-1-20140925/
https://www.w3.org/TR/2014/WD-css-flexbox-1-20140325/
https://www.w3.org/TR/2012/CR-css3-flexbox-20120918/
https://www.w3.org/TR/2012/WD-css3-flexbox-20120612/
https://www.w3.org/TR/2012/WD-css3-flexbox-20120322/
https://www.w3.org/TR/2011/WD-css3-flexbox-20111129/
https://www.w3.org/TR/2011/WD-css3-flexbox-20110322/
https://www.w3.org/TR/2009/WD-css3-flexbox-20090723/
A Visual Guide to CSS3 Flexbox Properties
**Thank:**The above demo forks from xluos的Flexbox Demo Station~
The Flex layout consists of two parts: the container flex container
and the item flex item
. The container has two axes by default: the horizontal spindle main axis
and the vertical cross axis cross axis
. The iterm defaults to the main axis.
The Flex property consists of two parts: the container property and the project property. The container can be set to: flex-direction
, flex-wrap
, flex-grow
, justify-content
, align-items
, align-content
6 attributes, six attributes can also be set on the item: order
, flex-grow
, flex-shrink
, flex-basis
, flex
, align-self
. An example is as follows:
function: determines the direction of the main axis.
flex-direction: row | row-reverse | column | column-reverse;
<script v-pre type="text/x-template" id="flexDirection"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { display: flex; flex-direction: row; } .item { width: 20%; height: 29px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; } </style> {{ radio.value }}
- row: The default value, the main axis is horizontal, indicating from left to right
- row-reverse: The main axis is horizontal, indicating from right to left
- column: The main axis is in the vertical direction, arranged from top to bottom
- column-reverse: The spindle is in the vertical direction, arranged from bottom to top
function: Decide how the item will wrap when it is not aligned on one axis.
flex-wrap: nowrap | wrap | wrap-reverse;
<script v-pre type="text/x-template" id="flexWrap"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { display: flex; flex-wrap: nowrap; } .item { width: 20%; height: 29px; max-width: 155px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; } </style> {{ radio.value }}
- nowrap: default value,not wrap
- wrap: wrap, the first line is above
- row-reverse: wrap, the first line is below
function: The abbreviation of flex-direction
and flex-wrap
properties, The default value is row nowrap
flex-wrap: <flex-direction> || <flex-wrap>;
- row nowrap: The default value, the main axis is horizontal, not wrap
<flex-direction>
: see flex-direction<flex-wrap>
: see flex-wrap
function: Define the alignment of the project on the spindle.
justify-content: flex-start | flex-end | center | space-between | space-round | space-evenly;
<script v-pre type="text/x-template" id="justifyContent"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { display: flex; justify-content: flex-start; } .item { width: 20%; height: 29px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; } </style> {{ radio.value }}
- flex-start: Default value, left aligned
- flex-end: Right aligned
- center: Centered
- space-evenly: The interval between each item and at both ends is equal
- space-around: Equal spacing on both sides of each item
- space-between: Aligned ends, the items are equally spaced
function: Defines the alignment of the item on the cross axis (the default direction is from top to bottom).
align-items: flex-start | flex-end | center | baseline | stretch;
<script v-pre type="text/x-template" id="alignItems"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { display: flex; align-items: stretch; } .item { width: 20%; height: 29px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; } </style> {{ radio.value }}
- flex-start: Starting point alignment of the cross axis
- flex-end: End point alignment of the cross axis
- center: center alignment of the cross axis
- baseline: Baseline alignment of the first line of text in the project
- stretch: The default value, when the item is not set to a fixed height, will fill the entire container
function: Defines the alignment of multiple axes. This property does not work if the project has only one axis.
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
<script v-pre type="text/x-template" id="alignContent"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { height: 399px; display: flex; flex-wrap: wrap; align-content: stretch; } .item { width: 20%; height: 29px; max-width: 155px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; } </style> {{ radio.value }}
- flex-start: Starting point alignment of the cross axis
- flex-end: End point alignment of the cross axis
- center: Center alignment of the cross axis
- space-between: Aligned with the ends of the cross shaft, the average spacing between the axes, etc.
- space-around: The spacing between the sides of each axis is equal
- stretch:Default, the axis fills the entire cross axis
function: Define the order in which the items are arranged.
order: <number>;
<script v-pre type="text/x-template" id="order"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { display: flex; } .item { width: 20%; height: 29px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; color: #f4f0ea; text-align: center; padding-top: 4px; } </style> 👉🏿🔀: {{ res }}
<number>
: The value is an integer. The smaller the value, the higher the ranking. The default is 0.
function: Define the scale of the project and allocate space to the project according to the ratio.
flex-grow: <number>;
<script v-pre type="text/x-template" id="flexGrow"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { display: flex; } .item { height: 29px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; color: #f4f0ea; text-align: center; padding-top: 4px; } </style> 👉🏿🔀: {{ res }}
<number>
: The value is an integer. The larger the value, the larger the space occupied by the project. The default is 0.
function: Define the contraction ratio of the project and allocate space to the project according to the ratio.
flex-shrink: <number>;
<script v-pre type="text/x-template" id="flexShrink"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { display: flex; } .item { width: 50%; height: 29px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; color: #f4f0ea; text-align: center; padding-top: 4px; } </style> 👉🏿🔀: {{ res }}
<number>
: The value is an integer. The larger the value, the smaller the space occupied by the item. The default is 0.
function: Defines the spindle space occupied by the project before allocating excess space. Based on this property, the browser calculates whether the spindle has extra space.
flex-basis: <length> | auto;
<script v-pre type="text/x-template" id="flexBasis"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { display: flex; } .item { width: 30%; height: 29px; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; color: #f4f0ea; text-align: center; padding-top: 4px; } </style> 👉🏿🔀: {{ res }}
<length>
: The default is auto, which is the original size of the project; you can also set the same value as the width or height properties (such as 329px), the project will occupy a fixed space.
function: The abbreviation of the flex-grow
,flex-shrink
and flex-basis
properties. The later two properties are optional.
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ];
0 1 auto
: default value, no scaling, proportional shrink if container space is insufficient1 1 auto
: Corresponding to the keywordauto
, if the container space is redundant, the extra space is allocated proportionally; if the container space is insufficient, the scale is shrinking.0 0 auto
: Corresponding to the keywordnone
, allocate space by the original size of the project
function: Define the alignment of individual items to override the align-items property.
align-self: auto | flex-start | flex-end | center | baseline | stretch;
<script v-pre type="text/x-template" id="alignSelf"> <style> main { width: 100%; padding: 52px 17px 52px 29px; } .container { height: 129px; display: flex; } .item { width: 20%; min-height: 29px; text-align: center; background: #b4a078; border-radius: 5px; margin: 12px; margin-left: 0; color: #f4f0ea; } </style> {{radio.value}}
- auto: The default value, which inherits the
align-items
attribute of the parent element. If there is no parent element, it is equivalent to the stretch.- flex-start: Starting point alignment of the cross axis
- flex-end: End point alignment of the cross axis
- center: Center point alignment of the cross axis
- baseline: Baseline alignment of the first line of text in the item
- stretch: If the fixed height is not set, it will fill the entire container