Skip to content

Flexbox

一句话解释

Flexbox 是 CSS 布局模块设计 for 排列元素 in one 维度 (行 or 列) 使用 powerful alignment capabilities.

用大白话说

Flexbox (Flexible Box Layout) is a CSS layout system that makes it easy to arrange elements in a single row or column. It solves problems that were hard with floats and inline-block: centering, equal spacing, distributing space, and reordering items.

To use Flexbox, you set display: flex on a container. Its children become "flex 项" that can be aligned, stretched, or spaced evenly. The container has a "主要 axis" (the direction of the items) and a "cross axis" (perpendicular to it).

Key properties include justify-内容 (alignment on the main axis), align-项 (alignment on the cross axis), flex-方向 (row or column), and flex-wrap (whether items wrap to the next line). Flexbox is the go-to tool for nav bars, card rows, and any 1D layout.

示例

css
.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
/* Items spread out with equal space between, vertically centered */

flex 容器使用项 evenly spaced and vertically centered — 常见布局模式.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表