What this article brings to you is about the properties of the CSS Flex layout (elastic layout). CSS Flex Layout Properties of the introduction, there is a certain reference value, the need for friends can refer to, I hope to help you.
Flex is the abbreviation for flexible box, meaning "resilient layout", which provides maximum flexibility for box-shaped models. Any container can be specified as a flex layout.
Note: When set to flex layout, the float, clear, and vertical-align properties of child elements are invalidated.
Basic concepts
Elements that use flex layouts, called Flex container, are referred to as "containers." All of its child elements automatically become container members, known as Flex items (Flex Item), or "project" for short.
The container has two axes by default: the horizontal spindle (main axis) and the vertical intersection axis (cross axis). The starting position of the spindle (the intersection with the border) is called main start, the end position is called the main end, the start position of the crossing axis is called Cross start, and the end position is called Cross end.
Container Properties
1. CSS Flex-direction
Flex-direction properties determine the direction of the spindle (that is, the direction of the project)
Flex-direction:row | Row-reverse | Column | Column-reverse
Row (default): The spindle is horizontal and the starting point is on the left side.
Row-reverse: The spindle is in the horizontal direction, starting at the right end.
Column: The spindle is in the vertical direction, starting at the top edge.
Column-reverse: The spindle is in the vertical direction, starting at the bottom edge.
2. CSS Flex-wrap (line wrapping)
Flex-wrap By default, items are lined up in a line (also known as the "axis"). The Flex-wrap property defines how to wrap a line if one of the axes does not fit.
Flex-wrap:nowrap | Wrap | Wrap-reverse;
NoWrap (default): No Line break.
Wrap: Wrap, the first line is above.
Wrap-reverse: Line break, the first line is below.
3. CSS Flex-flow
The Flex-flow property is a shorthand for the Flex-direction property and Flex-wrap property, and the default value is row nowrap.
Flex-flow: <flex-direction> | | <flex-wrap>;
4, Justify-content
The Justify-content property defines how the item is aligned on the spindle.
Justify-content:flex-start | Flex-end | Center | Space-between | Space-around;
Flex-start (default): Left Justified
Flex-end: Right-justified
Center: Center
Space-between: Justified, the interval between items is equal.
Space-around: The intervals on each side of the item are equal. Therefore, the interval between items is one times larger than the interval between items and borders.
5, Align-items
The Align-items property defines how the item is aligned on the intersection axis.
Align-items:flex-start | Flex-end | Center | Baseline | Stretch
Flex-start: The start alignment of the intersection axis.
Flex-end: The end alignment of the intersection axis.
Center: The midpoint alignment of the intersection axis.
Baseline: The baseline alignment of the first line of text for the item.
Stretch (default): If the item is not set to height or auto, it fills the height of the entire container.
6, Align-content
The Align-content attribute defines the alignment of multiple axes. If the item has only one axis, this property does not work.
Align-content:flex-start | Flex-end | Center | Space-between | Space-around | Stretch
Flex-start: Aligns with the starting point of the intersection axis.
Flex-end: Aligns with the end of the intersection axis.
Center: Aligns with the midpoint of the intersection axis.
Space-between: aligned with the intersection axis and evenly spaced between the axes.
Space-around: The intervals between each axis are equal. Therefore, the spacing between the axes is one times larger than the interval between the axes and the border.
Stretch (default): The axis fills the entire cross axis.
Project Properties
1. Order
The Order property defines the order in which the items are arranged. The smaller the number, the higher the alignment, and the default is 0.
2. CSS Flex-grow
The Flex-grow property defines the magnification of the item, which defaults to 0, that is, if there is space left, it is not zoomed in.
If all items have a Flex-grow property of 1, they will divide the remaining space (if any). If the Flex-grow property of one project is 2 and the other items are 1, the former occupies more than the remaining space.
* Can be used to achieve a two-point, three-point layout
3. CSS Flex-shrink
The Flex-shrink property defines the scaling of the project, which defaults to 1, which means that if there is not enough space, the project shrinks.
If all items have a Flex-shrink property of 1, they will be scaled down when there is not enough space. If the Flex-shrink property of an item is 0 and the other items are 1, the former does not shrink when there is not enough space.
A negative value is not valid for this property.
4. CSS Flex-basis
The Flex-basis property defines the spindle space (main size) that the item occupies before allocating the extra space. Based on this property, the browser calculates whether the spindle has extra space. Its default value is auto, which is the original size of the project.
It can be set to the same value as the width or height property (such as 350px), then the item will occupy a fixed space.
5. CSS Flex
Flex properties are shorthand for Flex-grow, Flex-shrink, and flex-basis, and the default value is 0 1 auto. The latter two properties are optional.
This property has two shortcut values: Auto (1 1 Auto) and none (0 0 Auto).
It is recommended that you use this property instead of writing three separate properties separately, because the browser calculates the relevant values.
6, Align-self
The Align-self property allows a single item to be aligned differently from other items, overriding the Align-items property. The default value is auto, which represents the Align-items property that inherits the parent element, and, if there is no parent element, is equivalent to stretch.