> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# align-content

APISummary
## 介绍

在[弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)中，`align-content` 定义了弹性行（flex line）在**交叉轴**上对齐方式。

在[网格布局](/next/zh/guide/ui/layout/grid-layout.md)中，`align-content` 定义了如何对齐网格轨道到**块轴**。

## 使用示例

**下面是一个示例: css-api**

**Entry:** `src/align-content`
**Bundle:** `dist/align-content.lynx.bundle`

```tsx
import { root } from "@lynx-js/react";
import "./index.scss";

const AlignContent = () => {
  const colorBlockStyle = (color: string) => ({
    width: "100px",
    height: "50px",
    backgroundColor: color,
  });

  const fixedAreaStyle = {
    width: "100%",
    height: "100%",
    flexDirection: "column" as const,
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view className="fixed_area" style={fixedAreaStyle}>
        <text>align-content:stretch;</text>
        <view className="container1">
          <view style={colorBlockStyle("red")} />
          <view style={colorBlockStyle("yellow")} />
          <view style={colorBlockStyle("green")} />
          <view style={colorBlockStyle("blue")} />
        </view>
        <text>align-content:center;</text>
        <view className="container2">
          <view style={colorBlockStyle("red")} />
          <view style={colorBlockStyle("yellow")} />
          <view style={colorBlockStyle("green")} />
          <view style={colorBlockStyle("blue")} />
        </view>
      </view>
    </scroll-view>
  );
};

root.render(<AlignContent />);

```

v0.11.0



## 语法

```css
/* Basic positional alignment */
/* align-content does not take left and right values */
align-content: center; /* Pack items around the center */
align-content: start; /* Pack items from the start */
align-content: end; /* Pack items from the end */
align-content: flex-start; /* Pack flex items from the start */
align-content: flex-end; /* Pack flex items from the end */

/* Distributed alignment */
align-content: space-between; /* Distribute items evenly
                                 The first item is flush with the start,
                                 the last is flush with the end */
align-content: space-around; /* Distribute items evenly
                                 Items have a half-size space
                                 on either end */
align-content: stretch; /* Distribute items evenly
                                 Stretch 'auto'-sized items to fit
                                 the container */
```

### 取值

#### `stretch`

**默认值**。如果元件沿交叉轴（[网格布局](https://developer.mozilla.org/zh/docs/Web/CSS/CSS_grid_layout)是块轴）的组合尺寸小于对齐容器的尺寸，任何对应尺寸设置为 `auto` 的元件的尺寸都会等比例地增加其尺寸（而不是按比例增加），可仍然遵守由 [`max-height`](/next/zh/api/css/properties/max-height.md)/[`max-width`](/next/zh/api/css/properties/max-width.md)（或相应功能）施加的约束，以便沿交叉轴（网格布局是块轴）完全填充对齐容器的组合尺寸。

#### `start`

所有行从容器的起始边缘开始填充。

#### `end`

所有行从容器的结束边缘开始填充。

#### `flex-start`

同 `start` 表现一致。建议只在弹性布局上使用。

#### `flex-end`

同 `end` 表现一致。建议只在弹性布局上使用。

#### `center`

所有行朝向容器的中心填充。每行互相紧挨，相对于容器居中对齐。容器的交叉轴（[网格布局](https://developer.mozilla.org/zh/docs/Web/CSS/CSS_grid_layout)是块轴）起点边和第一行的距离相等于容器的交叉轴（网格布局是块轴）终点边和最后一行的距离。

#### `space-between`

所有行在容器中平均分布。相邻两行间距相等。容器的交叉轴（[网格布局](https://developer.mozilla.org/zh/docs/Web/CSS/CSS_grid_layout)是块轴）起点边和终点边分别与第一行和最后一行的边对齐。

#### `space-around`

所有行在容器中平均分布，相邻两行间距相等。容器的交叉轴（[网格布局](https://developer.mozilla.org/zh/docs/Web/CSS/CSS_grid_layout)是块轴）起点边和终点边分别与第一行和最后一行的距离是相邻两行间距的一半。

## 形式定义

| 初始值 | `stretch` |
| 适用元素 | 弹性容器和网格容器 |
| 是否支持继承 | 否 |
| 是否支持动画 | 否 |


## 形式语法

```
align-content = stretch | start | end | flex-start | flex-end | center | space-between | space-around
```

## 与 Web 的区别

[mdn: align-content](https://developer.mozilla.org/zh-CN/docs/Web/CSS/align-content)

1. 不支持 `normal`、`baseline`、`first baseline`、`last baseline`，默认值为 `stretch`。
2. 不支持 `space-evenly`，后续会支持。

## 兼容性

**Compatibility Table**

**Query:** `css.properties.align-content`

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/57-align-content.json) · [MDN](https://developer.mozilla.org/zh-CN/docs/Web/CSS/align-content)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| align-content | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| unsupported&#95;value&#95; | No | No | No | No | No | Yes |
| supported&#95;in&#95;flex&#95;layout | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| supported&#95;in&#95;flex&#95;layout.nested&#95;value&#95;1 | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| supported&#95;in&#95;flex&#95;layout.nested&#95;value&#95;2 | Yes (2.1) | Yes (3.4) | Yes (2.1) | Yes (2.1) | Yes (2.1) | Yes |
| supported&#95;in&#95;grid&#95;layout | Yes (2.1) | Yes (3.4) | Yes (2.1) | Yes (2.1) | Yes (2.1) | Yes |
| supported&#95;in&#95;grid&#95;layout.nested&#95;value&#95;1 | Yes (2.1) | Yes (3.4) | Yes (2.1) | Yes (2.1) | Yes (2.1) | Yes |
| supported&#95;in&#95;grid&#95;layout.nested&#95;value&#95;2 | Yes (2.1) | Yes (3.4) | Yes (2.1) | Yes (2.1) | Yes (2.1) | Yes |

**`align-content`**

**Specifications:**

**`unsupported_value_`**

<code>normal</code>, <code>space-evenly</code>

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/57-align-content.json)

**`supported_in_flex_layout`**

Supported in Flexible Box Layout

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/57-align-content.json)

**`supported_in_flex_layout.nested_value_1`**

<code>stretch</code>, <code>flex-start</code>, <code>flex-end</code>, <code>center</code>, <code>space-between</code> and <code>space-around</code>

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/57-align-content.json)

**`supported_in_flex_layout.nested_value_2`**

<code>start</code> and <code>end</code>

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/57-align-content.json)

**`supported_in_grid_layout`**

Supported in Grid Layout

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/57-align-content.json)

**`supported_in_grid_layout.nested_value_1`**

<code>stretch</code>, <code>flex-start</code>, <code>flex-end</code>, <code>center</code>, <code>space-between</code> and <code>space-around</code>

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/57-align-content.json)

**`supported_in_grid_layout.nested_value_2`**

<code>start</code> and <code>end</code>

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/57-align-content.json)

