Home Web Front-end CSS Tutorial flex layout – review

flex layout – review

Feb 13, 2017 pm 02:46 PM
flex

flex is flexible layout.
Any container can be designated as flex layout.
  .box{display:flex}
Inline elements can use flex layout
 .box{display: inline-flex}
Browsers with webkit kernel must add the -webkit prefix.
  .box{display:-webkit-flex; display:flex;}
Note: After an element is set to flex layout, the float, clear and vertical-align attributes of the child elements will be invalid.
Basic concept:
An element that uses flex layout is called a flex container, and all its child elements automatically become container members, called flex
items.
The container has two axes by default, the horizontal main axis (main axis) and the vertical cross axis (cross axis). The starting position of the main axis (the intersection with the frame) is called main start, and the ending position is called main end;
The starting position of the cross axis is called cross start, the ending position is called cross start, and the technical position is called cross end.
Single project The main axis space occupied is called main size and the cross axis space occupied is called cross size.

Container properties:
There are 6 properties set on the container.
flex-direction flex-wrap flex-flow justify-content
align-items align-content
1.flex-direction
The property determines the direction of the main axis (i.e. the arrangement direction of the items)
.box{flex-direction:row | row-reverse | column | column-reverse;}
row (default value) The main axis is horizontal and the starting point is at the left end.
       row-reverse: The main axis is horizontal and the starting point is at the right end.
    column: The main axis is vertical, and the starting point is on the upper edge.
      column-reverse: The main axis is vertical and the starting point is at the lower edge.
  2.flex-wrap attribute
   By default, items are arranged on a line (also called an axis). The flex-wrap attribute defines how to wrap the line if an axis line
cannot be arranged.
       .box{flex-wrap: nowrap | wrap | wrap-reverse;}
                                                               .box{flex-wrap: nowrap |
        wrap: Wrap: line wrap, with the first line at the top.
        wrap-reverse: Wrap, first line below.
   3.flex-flow
    The flex-flow attribute is the abbreviation of the flex-direction attribute and the flex-wrap attribute. The default value is row nowrap.
    .box{ flex-flow:;}
    4.justify-content attribute
                                                          ] Because justified-content attribute
    The attribute defines the alignment of the item on the main axis.
    .box{justify-content: flex-start | flex-end | center | space-between | space-around;}
5 values, the specific alignment is related to the direction of the axis. It is assumed below that the main axis is the slave Left to right.
Flex-Start (default value): Left 对
Flex-End Right lying
Center 居
Space-Between: Align in both ends, and the interval between the projects is equal.
Space-around: The space on both sides of each item is equal, so the space between items is twice as large as the space between the items and the border.
  5.align-items
    The attribute defines how the items are aligned on the cross axis.
     .box{align-items: flex-start | flex-end | center | baseline | stretch;}
It may take 5 values. The specific alignment method is related to the direction of the cross axis. The following assumes that on the cross axis From top to bottom.
       flex-start: Align the starting point of the cross axis.
       flex-end: Align the end point of the cross axis.
     center: Align the midpoint of the intersection week.
      baseline: Baseline alignment of the first line of text of the item.
    stretch (default value) If the item does not set a height or sets auto, it will occupy the entire height of the container.
   6.align-content attribute
     The attribute defines the alignment of multiple axes. If the project can only have one axis, this attribute will not work.
     .box{align-content: flex-start | flex-end | center | space-between | space-around |
     stretch;}
     The attribute can take on 6 values.
       flex-start: Aligned with the starting point of the cross axis.
       flex-end: Aligned with the end point of the cross axis.
      center: Aligned with the midpoint of the cross axis.
Space-between; Align with both ends of the cross axis, and the intervals between the axes are evenly distributed.
       space-around: The intervals on both sides of each axis are equal.

     stretch(default value): The axis line occupies the entire cross axis.


Project properties
You can set 6 properties on the project.

Order flex-grow flex-shrink flex-basis flex align-self###

   1.order attribute
     order attribute defines the sorting order of items. The smallest value is, the higher the arrangement is. The default is o.
   .item { order: ;}
    2.flex -grow attribute
The flex-grow attribute defines the magnification ratio of the item. The default is 0, that is, if there is remaining space, it will also be enlarged.
     .item { flex-grow: ;}
     If all items have a flex-grow attribute of 1, they will enclose the remaining space. If an item's flex-grow attribute is 1 2. If all other items are 1, the former will occupy twice as much remaining space as other items.

3.flex-shrink attribute

The flex-shrink attribute defines the shrinkage ratio of the item. The default is 1, which means there is insufficient space, and the item will be shrunk.
      .item{flex-shrink:;}
                                             If the flex-shrink property of all items is 1, when there is insufficient space, they will all be reduced proportionally.
                                        If the flex-shrink attribute of an item is o and other items are 1, then when there is insufficient space, the former
will not shrink. Negative values ​​are not valid for this property.
    4.flex-basis attribute
                                                   cco wealth willoy' '' The property defines the main axis space occupied by the item before allocating excess space. Based on this attribute, the browser calculates
whether there is excess space on the main axis. Its default value is auto, which is the original size of the project.
    .item {flex-basis: | auto;}
     It can be set to some value similar to the width or height attribute, then the item will occupy a fixed space.
   5.flex attribute
                                           
     .item { flex:none | [<'flex-grow'> <'flex-shrink'> ? || <'flex-basis'>]}
    This attribute has two There are two shortcut values: auto (1 1 auto) and none (0 0 auto).
                                        
     Because the browser will calculate the relevant values
If other items have different alignments, you can override the align attribute. The default value is auto, which means inheriting the align-items attribute of the parent element.
If there is no parent element, it is equal to stretch.
self: auto | flex-start | flex-end | center | baseline | stretch;}
This attribute may take 6 values. Except for auto, the others are exactly the same as the align-items attribute.

For more flex layout - to review related articles, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Take you step by step to implement 3D dice using CSS Flex and Grid layout (with code) Take you step by step to implement 3D dice using CSS Flex and Grid layout (with code) Sep 23, 2022 am 09:58 AM

In front-end interviews, we are often asked how to implement dice/mahjong layout using CSS. The following article will introduce to you how to use CSS to create a 3D dice (Flex and Grid layout implement 3D dice). I hope it will be helpful to you!

What are the commonly used Flex layout properties? What are the commonly used Flex layout properties? Feb 25, 2024 am 10:42 AM

What are the common properties of flex layout? Specific code examples are required. Flex layout is a powerful tool for designing responsive web page layouts. It makes it easy to control the arrangement and size of elements in a web page by using a flexible set of properties. In this article, I will introduce the common properties of Flex layout and provide specific code examples. display: Set the display mode of the element to Flex. .container{display:flex;}flex-directi

An article explaining in detail the impact of three flex properties on elements An article explaining in detail the impact of three flex properties on elements Aug 30, 2022 pm 07:50 PM

During development, the flex attribute is often used to act on the child elements of the flexible box, such as: flex:1 or flex: 1 1 auto. So how does this attribute control the behavior of the element? What exactly does flex:1 mean? Let this article take you through a thorough understanding of the flex property!

Take you through the three attributes of Flex layout: flex-grow, flex-shrink, flex-basis Take you through the three attributes of Flex layout: flex-grow, flex-shrink, flex-basis Dec 06, 2022 pm 08:37 PM

This article will give you an in-depth understanding of the three properties of CSS Flex layout: flex-grow, flex-shrink, and flex-basis. I hope it will be helpful to you!

How to achieve sliding menu effect through CSS Flex layout How to achieve sliding menu effect through CSS Flex layout Sep 26, 2023 pm 02:13 PM

How to achieve the sliding menu effect through CSSFlex elastic layout. In web design, sliding menu is a common interactive effect, which can make the web page more smooth and beautiful. This article will teach you how to use CSSFlex elastic layout to achieve this effect, and provide specific code examples. CSSFlex is a new layout method that can easily achieve various complex layout effects. It controls the layout by setting the properties of the container and child elements, of which the flex property is one of the most important properties. First, we need a

Detailed explanation of grid spacing and border processing methods in CSS Flex flexible layout Detailed explanation of grid spacing and border processing methods in CSS Flex flexible layout Sep 26, 2023 am 10:31 AM

Title: Detailed explanation of grid spacing and border processing methods in CSSFlex elastic layout Introduction: CSSFlex elastic layout is a modern page layout method that allows web pages to automatically adapt to different screen sizes and is flexible and responsive. When using CSSFlex flexible layout, we often encounter situations where we need to set grid spacing and borders. This article will introduce in detail the grid spacing and border processing methods in CSSFlex flexible layout, and provide specific code examples. 1. Grid spacing

A detailed explanation of Flex layout in CSS3 A detailed explanation of Flex layout in CSS3 Nov 01, 2022 pm 07:29 PM

This article will take you through the Flex layout in CSS3, I hope it will be helpful to you!

CSS adaptive layout property optimization tips: flex and grid CSS adaptive layout property optimization tips: flex and grid Oct 21, 2023 am 08:03 AM

CSS adaptive layout attribute optimization tips: flex and grid In modern web development, implementing adaptive layout is a very important task. With the popularity of mobile devices and the diversification of screen sizes, it is an essential requirement to ensure that the website can be displayed well on various devices and adapt to different screen sizes. Fortunately, CSS provides some powerful properties and techniques for implementing adaptive layout. This article will focus on two commonly used properties: flex and grid, and provide specific code examples.

See all articles