Flexbox 完全指南_html/css_WEB-ITnose
Flexbox 完全指南
我不是这篇文章的原创作者,我只是好文章的搬运工。原文地址 A Complete Guide to Flexbox
应用于 flex container 的属性
display
该属性定义一个 flex container,根据不同取值定义为 inline 或 block 的 flex container。应用了该属性的元素为它的所有子元素创建了一个 flex context。
.container { display: flex; /* or inline-flex */}
注意,CSS3 的多列布局对 flex 容器没有任何影响。
flex-direction
该属性建立主轴,规定了 flex container 中的 flex item 的排布方向。Flexbox 是一种单向布局概念,可以认为 flex item 都优先沿着水平行或竖直列布局。
.container { flex-direction: row | row-reverse | column | column-reverse;}
flex-wrap
默认情况下,所有的 flex item 都将尽量保持在一个 line (行或者列,下同)之内。可以通过这个属性让 flex item 在需要的情况下换行或者换列。这里,新行或新列从哪里开始由 flex-direction 决定。
.container{ flex-wrap: nowrap | wrap | wrap-reverse;}
flex-flow
该属性为 flex-direction 和 flex-wrap 的简写属性,同时定义了 flex container 的主轴和交叉轴。默认值为 row nowrap。
flex-flow: <‘flex-direction’> || <‘flex-wrap’>
justify-content
该属性定义了沿着主轴的对齐方式。它被用来处理当所有 flex item 都已经放置完毕后的剩余空白空间。
.container { justify-content: flex-start | flex-end | center | space-between | space-around;}
align-items
该属性定义了在当前 line 中 flex item 沿着交叉轴布局的默认行为。可以认为它是针对交叉轴的 justify-content。
.container { align-items: flex-start | flex-end | center | baseline | stretch;}
align-content
该属性用来在交叉轴还有空白空间的情况下控制 flex container 内的所有 line 的对齐方式。与 justify-content 控制 flex item 如何沿着主轴方向对齐的方式类似。
注意: 单 line 情况下,该属性不生效。
.container { align-content: flex-start | flex-end | center | space-between | space-around | stretch;}
应用于 flex item 的属性
order
在默认情况下,所有的 flex items 按照源代码中定义的顺序布局。但是, order 属性控制了 flex item 在 flex container 中显示的优先级。
.item { order: <integer>;}
flex-grow
该属性赋予 flex item 生长(grow)的能力。它接受一个无单位的值,并将其作为比例值,表示在 flex container 中,这个 flex item 能够占有多大比例的可用空间。
如果所有的 flex item 的 flex-grow 属性都设置为1,那么 container 的剩余空间将被均匀的分配给所有 flex item。如果当中有一个 item 的 flex-grow 属性设置为2,那么 这个 item 将占有2倍于其他 item 占有的可用空间。
.item { flex-grow: <number>; /* default 0 */}
负值是非法取值。
flex-shrink
该属性赋予 flex item 在必要的情况下收缩的能力。
.item { flex-shrink: <number>; /* default 1 */}
负值是非法取值。
flex-basis
该属性用于在分配剩余空间之前定义 flex item 的默认尺寸大小。它的取值可以为一个绝对长度值(比如 20%,5rem,等)或者是一个关键字。auto 关键字表示根据 flex item 自身的 width 和 height 属性取值确定。 content 关键字表示根据 flex item 的 content 来确定,但是目前并没有得到很好的支持。
.item { flex-basis: <length> | auto; /* default auto */}
如果该属性取值为0,那么在该 flex item 的 content 周围的额外空间将不被计算在内。如果取值为 auto,那么 flex item 的大小将根据 flex-grow 的取值来确定。可以参考这张图。
flex
该属性为 flex-grow, flex-shrink 和 flex-basis 的混合简写方式。 其中第二个和第三个参数(flex-shrink 和 flex-basis)为可选参数。该属性的默认值为 0 1 auto。
.item { flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]}
align-self
该属性可以为每个 flex item 指定对齐方式。我们可以通过该属性修改 flex item 默认的或者由 align-items 指定的对齐方式。它的取值说明参考 align-items 的取值说明。
.item { align-self: auto | flex-start | flex-end | center | baseline | stretch;}
注意,float,clear 和 vertical-align 对 flex item 无任何影响。
更多实例请参考原文例子。

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

AI Hentai Generator
Generate AI Hentai for free.

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

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex
