Display:flex Elastic Telescopic Layout detailed

Source: Internet
Author: User

The traditional solution for layout, based on the box model, depends on the Display property + Position property + Float property. It is very inconvenient for those special layouts, for example, vertical centering is not easy to achieve. One, what is the flex layout.

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.

[CSS] view plain copy. box1{Display:flex;  }. box2{Display:inline-flex; <span style= "font-family:arial, Helvetica, Sans-serif;" >/*</span><span style= "font-family:arial, Helvetica, Sans-serif;" > Inline elements can also use the flex layout. */</span>}. box3{display:-webkit-flex;/* Safari, WebKit kernel browser, must be prefixed with-webkit.   */Display:flex; }

The difference between style attributes, Display:flex; and Display:inline-flex;

Display:flex; Elements into block-level elements
Display:inline-flex; Elements into inline block-level elements

Although the container is different, the items in the container are the same. Note: When set to flex layout, the float, clear, and vertical-align properties of child elements are invalidated.

Ii. Basic ConceptsElements 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: horizontalSpindle(main axis) and the verticalCross 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.
The project is arranged by default along the spindle. The main axis space occupied by a single item is called the main size, and the occupied intersection space is called cross size.
third, the container propertiesFlex-direction flex-wrap flex-flow justify-content align-items align-content3.1 flex-direction PropertiesThe Flex-direction property determines the direction of the spindle (that is, the direction in which the item is arranged).
[CSS]View plain copy. Box {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.
3.2flex-wrap PropertyBy 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.
[CSS]View plain copy. box{flex-wrap:nowrap | wrap | wrap-reverse; } (1) nowrap (default): No Line break. (2) Wrap: Wrap, the first line is above.

(3) Wrap-reverse: line break, the first line is below.


3.3 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.

[CSS]View plain copy. Box {flex-flow: <flex-direction> | | <flex-wrap>; }
3.4 Justify-content Properties
The Justify-content property defines how the item is aligned on the spindle.


[CSS]View plain copy. Box {justify-content:flex-start | flex-end | center | space-between | space-around; } flex-start (default): Left justified Flex-end: right-aligned center: centered 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.

3.5 Align-items Properties The Align-items property defines how the item is aligned on the intersection axis

[CSS]View plain copy. Box {align-items:flex-start | flex-end | center | baseline | stretch; } Flex-start: The start of the intersection axis is aligned. 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 [strɛtʃ] (default): If the item is not set to height or auto, it fills the height of the entire container. The 3.6 Align-content Property Align-content property defines the alignment of multiple axes. If the item has only one axis, this property does not work.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.