Flex elastic box model, flex elastic

Source: Internet
Author: User

Flex elastic box model, flex elastic

Flex refers to the elastic layout, which is used to provide the maximum flexibility for the box model. It specifies the items in the container as the elastic layout, similar to float: left;

The advantage of float is that the container does not set the height and will adapt to the height based on the project. We all know that if the float attribute is set, the container will leave the Document Stream and need to clear the float, according to the height of the project.

The parent element is called a container, and the child element is called a project.

The horizontal direction is called the spindle, and the horizontal and vertical intersections are called the cross axis.

In flex, if the total width of the fruit element does not exceed the parent width, it will be arranged normally. In flex, if the total width of the fruit element exceeds the parent width, it will be evenly allocated according to the parent width, in addition, it is not affected by the border and padding. The following code sets display: flex, and items in the container are automatically left floating, and ul does not set the height,

 


Effect

Flex-direction attributes change determines the direction of the project (I .e. sub-elements) Arrangement

 

Row (default value) Horizontal Direction left to left as the starting point

The row-reverse horizontal direction is arranged at the right end point

Code

Effect

The vertical direction of column. The starting point is in the upper left corner.

Code

Effect

Column-reverse vertical direction, starting from below, similar to turning the child element

Code

Effect

Flex-wrap: This attribute is set for wrap. If the width of the child element exceeds the width of the parent element, a line break is generated.

As mentioned above, we have set dispay: flex. In flex, if the total width of the fruit element does not exceed the parent level, it will be arranged normally (in actual pixels ),

In flex, if the total width of the fruit element exceeds that of the parent element, the width is equal to the width of the parent element (by percentage, in addition, it is not affected by the border and padding. Sometimes, even if the width of the child element exceeds the width of the parent element, we want to wrap the child element according to the actual pixel instead of the percentage, then we can set flex-wrap. The total width of the child element under wrap obviously exceeds the total width of the parent element, and the excess is arranged according to the percentage of the parent element width, the actual width of the child element is invalid.

 

Effect

 

In this case, even if the width of the child element exceeds the width of the parent element, the actual width of the child element is arranged without percentages. Here we can set flex-wrap: you can use the wrap attribute.

 

The effect is as follows:

As you can see, if flex-wrap: wrap is set, the width of the child element exceeds the width of the parent element. The child element is arranged according to the actual width of the child element, and the line feed is displayed.


 

Related Article

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.