search
HomeWeb Front-endCSS TutorialWhat are the properties of css flex layout (elastic layout)? Introduction to css flex layout properties

What this article brings to you is what are the properties of css flex layout (elastic layout)? The introduction of css flex layout properties has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Flex is the abbreviation of Flexible Box, which means "flexible layout" and is used to provide maximum flexibility for box-shaped models. Any container can be designated as a Flex layout.
Note: After setting to Flex layout, the float, clear and vertical-align attributes of child elements will be invalid.

Basic concepts

Elements that use Flex layout are called Flex containers (flex containers), referred to as "containers". All its child elements automatically become container members, called Flex items (flex items), or "items" for short.
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 border) is called main start, and the ending position is called main end; the starting position of the cross axis is called cross start, and the ending position is called cross end.

Container attribute

1. css flex-direction

The flex-direction attribute determines the main axis The direction (that is, the arrangement direction of the items)
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. css flex-wrap (line wrap)

flex-wrap By default, items are arranged on a line (also called "axis"). The flex-wrap attribute defines how to wrap if one axis cannot fit.
flex-wrap: nowrap | wrap | wrap-reverse;
nowrap (default): no line wrapping.
wrap: wrap, with the first line at the top.
wrap-reverse: wrap, the first line is below.

3. css 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.
flex-flow: || ;

4.justify-content

justify-content attribute definition Aligns the item on the main axis.
justify-content: flex-start | flex-end | center | space-between | space-around;
flex-start (default value): left-aligned
flex-end: right-aligned
center: Center
Space-between: Align both ends, and the intervals between items are equal.
space-around: The space on both sides of each item is equal. Therefore, the space between items is twice as large as the space between items and the border.

5. align-items

The align-items attribute defines how items are aligned on the cross axis.
align-items: flex-start | flex-end | center | baseline | stretch;
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 cross axis.
baseline: The baseline alignment of the first line of text of the item.
​ stretch (default value): If the item does not set a height or is set to auto, it will occupy the entire height of the container.

6. align-content

The align-content attribute defines the alignment of multiple axes. If the item has only one axis, this property has no effect.
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
flex-start: with the cross axis aligned with the starting point.
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. Therefore, the distance between the axes is twice as large as the distance between the axes and the frame.
stretch (default value): The axis occupies the entire cross axis.

Item attributes

1. order

The order attribute defines the order of items. The smaller the value, the higher the ranking. The default is 0.

2, css flex-grow

The flex-grow attribute defines the enlargement ratio of the item. The default is 0, that is, if there is remaining space, it will not be enlarged.
If all items have a flex-grow property of 1, they will equally divide the remaining space (if there is any). If one item's flex-grow property is 2 and the other items are all 1, the former will occupy twice as much remaining space as the other items.
*Can be used to implement two-point and three-point layout

3. css flex-shrink

The flex-shrink attribute defines the reduction ratio of the item, the default is 1, i.e. if there is insufficient space, the item will 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 property of one item is 0 and the other items are 1, the former will not shrink when there is insufficient space.
Negative values ​​are not valid for this attribute.

4. css flex-basis

The flex-basis property defines the main axis space (main size) occupied by the item before allocating excess space. The browser uses this attribute to calculate whether there is extra space on the main axis. 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 attribute (such as 350px), then the item will occupy a fixed space.

5. css flex

The flex property is the abbreviation of flex-grow, flex-shrink and flex-basis. The default value is 0 1 auto. The last two properties are optional.
This attribute has two shortcut values: auto (1 1 auto) and none (0 0 auto).
It is recommended to give priority to using this attribute instead of writing three separate attributes separately, because the browser will infer the relevant values.

6. align-self

The align-self attribute allows a single item to have a different alignment than other items and can override the align-items 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 equivalent to stretch.

Related recommendations:

##CSSOld versionflexand compatible_html/css_WEB-ITnose

CSS Flex-box sample code_html/css_WEB-ITnose

CSSFlexible box modelflexApplication in layout

The above is the detailed content of What are the properties of css flex layout (elastic layout)? Introduction to css flex layout properties. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
Two Images and an API: Everything We Need for Recoloring ProductsTwo Images and an API: Everything We Need for Recoloring ProductsApr 15, 2025 am 11:27 AM

I recently found a solution to dynamically update the color of any product image. So with just one of a product, we can colorize it in different ways to show

Weekly Platform News: Impact of Third-Party Code, Passive Mixed Content, Countries with the Slowest ConnectionsWeekly Platform News: Impact of Third-Party Code, Passive Mixed Content, Countries with the Slowest ConnectionsApr 15, 2025 am 11:19 AM

In this week's roundup, Lighthouse sheds light on third-party scripts, insecure resources will get blocked on secure sites, and many country connection speeds

Options for Hosting Your Own Non-JavaScript-Based AnalyticsOptions for Hosting Your Own Non-JavaScript-Based AnalyticsApr 15, 2025 am 11:09 AM

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

It's All In the Head: Managing the Document Head of a React Powered Site With React HelmetIt's All In the Head: Managing the Document Head of a React Powered Site With React HelmetApr 15, 2025 am 11:01 AM

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its

What is super() in JavaScript?What is super() in JavaScript?Apr 15, 2025 am 10:59 AM

What's happening when you see some JavaScript that calls super()?.In a child class, you use super() to call its parent’s constructor and super. to access its

Comparing the Different Types of Native JavaScript PopupsComparing the Different Types of Native JavaScript PopupsApr 15, 2025 am 10:48 AM

JavaScript has a variety of built-in popup APIs that display special UI for user interaction. Famously:

Why Are Accessible Websites so Hard to Build?Why Are Accessible Websites so Hard to Build?Apr 15, 2025 am 10:45 AM

I was chatting with some front-end folks the other day about why so many companies struggle at making accessible websites. Why are accessible websites so hard

The `hidden` Attribute is Visibly WeakThe `hidden` Attribute is Visibly WeakApr 15, 2025 am 10:43 AM

There is an HTML attribute that does exactly what you think it should do:

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.