A brief introduction to Flex layout of display attribute in CSS3
This article brings you a brief introduction to the Flex layout of the display attribute in CSS3. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Recently I am learning WeChat applet. When designing the layout of the homepage, I came across a new layout method display:flex
.container { display: flex; flex-direction: column; align-items: center; background-color: #b3d4db; }
The effect after compilation is very obvious, and the layout of the interface is also very reasonable. , looks very clear. So what is this attribute used for?
Flex is the abbreviation of Flexible Box, which means "flexible layout" and is used to provide maximum flexibility for box-shaped models. After setting to Flex layout, the float
, clear
and vertical-align
attributes of the child elements will be invalid.
It can be applied to containers or inline elements. (The above description is combined with the WeChat developer tool description) In 2009, W3C proposed a new solution-Flex layout, which can implement various page layouts simply, completely, and responsively. Currently, it is supported by all browsers, which means it is now safe to use this feature.
Basic concepts
Elements that adopt Flex layout are called Flex containers (flex containers), or "containers" for short. All its child elements automatically become container members, called Flex items (flex items), referred to as "items". The container has two axes by default: the horizontal main axis and the vertical 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 It’s called cross end
. Items are arranged along the main axis by default. The main axis space occupied by a single project is called main size
, and the cross axis space occupied by a single item is called cross size
.
The following 6 properties are set on the container:
flex-direction The arrangement direction of the items in the container (default horizontal arrangement)
flex-wrap The wrapping method of items in the container
flex-flow The abbreviation of the above two properties
justify-content The alignment of items on the main axis
align-items Item How to align on the cross axis
align-content Defines the alignment of multiple axes. This property has no effect if the project has only one axis.
flex-direction
## 1 .box { 2 flex-direction: row | row-reverse | column | column-reverse; 3 }
The optional value range of the attribute is row (default) arranged from left to right along the horizontal main axis, row-reverse arranged from right to left along the horizontal main axis, column from top right to bottom along the vertical main axis, and column-reverse.flex-wrap 1 .box{ 2 flex-wrap: nowrap | wrap | wrap-reverse; 3 }
The optional value range of the attribute is nowrap (default ) no line wrapping, wrap wrapping (the first line is at the top) and wrap-reverse (you know~)flex-flow
1 .box { 2 flex -flow:justify-content
1 .box { 2 justify-content: flex-start | flex-end | center | space-between | space-around; 3 }
The alignment of the items on the main axis (which axis the main axis is depends on the setting of the attribute flex-direction)flex-start: Arrange from left or top on the main axisflex-end: Arrange from the right or bottom on the main axis center: Arrange in the center on the main axis space-between: Start from the left and right ends or the upper and lower ends of the main axis Arrangespace-around: Each item is equally spaced on both sides. Therefore, the space between items is twice as large as the space between items and the border. align-items 1 .box { 2 align-items: flex-start | flex-end | center | baseline | stretch; 3 } Go directly here The picture illustrates it more clearly
flex-basis 在分配多余空间之前,项目占据的主轴空间(main size)。浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为auto,项目的本来大小。
flex 是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选。
align-self 允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items属性。默认值为auto,表示继承父元素的align-items属性,如果没有父元素,则等同于stretch。
order
1 .item { 2 order: <integer>; 3 }
flex-grow
1 .item { 2 flex-grow: <number>; /* default 0 */ 3 }
flex-shrink
1 .item { 2 flex-shrink: <number>; /* default 1 */ 3 }
flex-basis
1 .item { 2 flex-basis: <length> | auto; /* default auto */ 3 }
flex
1 .item { 2 flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ] 3 }
align-self
1 .item { 2 align-self: auto | flex-start | flex-end | center | baseline | stretch; 3 }
容器属性和项目属性是可以配合使用的,用法类似于CSS的行内式和嵌入式的道理一样。希望你可以在实际应用中熟练使用。
相关推荐:
CSS选择器的代码实例以及css优先级的代码实例The above is the detailed content of A brief introduction to Flex layout of display attribute in CSS3. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there's a bit of a learning curve, but Grid is
