> 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-self

APISummary
## 介绍

[弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)、[线性布局](/next/zh/guide/ui/layout/linear-layout.md)中，`align-self` 会在**交叉轴上**对齐当前容器中的元件。[网格布局](/next/zh/guide/ui/layout/grid-layout.md)中，`align-self` 控制子元件在其网格区域（grid area）内的**块向轴**上的对齐，且 `align-self` 会覆盖已有的 [`align-items`](/next/zh/api/css/properties/align-items.md) 的值。

对于[弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)，如果任何子元件的交叉轴方向 [`margin`](/next/zh/api/css/properties/margin.md) 值设置为 auto，则会忽略 `align-self`。

:::info
对于[网格布局](/next/zh/guide/ui/layout/grid-layout.md)，Lynx 不支持 `writing-mode`，所以块轴就是垂直轴。
:::

## 使用示例

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

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

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

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

  const itemStyle = {
    width: "50px",
    height: "50px",
    margin: "5px",
    backgroundColor: "#4e98f4",
    color: "#ffffff",
    textAlign: "center" as const,
    lineHeight: "50px",
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view className="fixed_area" style={fixedAreaStyle}>
        <view style={{ width: "100%", height: "100%", flexDirection: "column" }}>
          <text className="title">align-self: stretch;</text>
          <view style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
            <text style={itemStyle}>X</text>
            <text style={{ ...itemStyle, alignSelf: "stretch" }}>X</text>
            <text style={itemStyle}>X</text>
          </view>

          <text className="title">align-self: center;</text>
          <view style={{ display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
            <text style={itemStyle}>X</text>
            <text style={{ ...itemStyle, alignSelf: "center" }}>X</text>
            <text style={itemStyle}>X</text>
          </view>

          <text className="title">align-self: flex-start;</text>
          <view style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
            <text style={itemStyle}>X</text>
            <text style={{ ...itemStyle, alignSelf: "flex-start" }}>X</text>
            <text style={itemStyle}>X</text>
          </view>

          <text className="title">align-self: flex-end;</text>
          <view style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
            <text style={itemStyle}>X</text>
            <text style={{ ...itemStyle, alignSelf: "flex-end" }}>X</text>
            <text style={itemStyle}>X</text>
          </view>
        </view>
      </view>
    </scroll-view>
  );
};

root.render(<AlignSelf />);

```

v0.11.0



## 语法

```css
/* 基本关键字 */
align-self: stretch;
align-self: auto;

/* 定位对齐 */
align-self: center;
align-self: start;
align-self: end;
align-self: flex-start;
align-self: flex-end;

/* 基线对齐 */
align-self: baseline;
```

### 取值

#### `auto`

**默认值**。根据 [`align-items`](/next/zh/api/css/properties/align-items.md) 定义的方式对齐。

#### `stretch`

元件在**交叉轴**（[网格布局](/next/zh/guide/ui/layout/grid-layout.md)是块轴）方向上未设置尺寸（高度/宽度）或设为 `auto`，会被拉伸到与行相同的高度或列相同的宽度。同时这些元件仍然保持其宽高比例的约束。

#### `center`

在[弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)、[线性布局](/next/zh/guide/ui/layout/linear-layout.md)中，元件在交叉轴居中。

在[网格布局](/next/zh/guide/ui/layout/grid-layout.md)中，元件在网格区域的块轴方向上居中。

#### `start`

在[弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)、[线性布局](/next/zh/guide/ui/layout/linear-layout.md)中，元件在交叉轴上对齐起始位置。

在[网格布局](/next/zh/guide/ui/layout/grid-layout.md)中，元件在块轴上与网格区域的起始边缘对齐。

#### `end`

在[弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)、[线性布局](/next/zh/guide/ui/layout/linear-layout.md)中，元件在交叉轴上对齐结尾位置。

在[网格布局](/next/zh/guide/ui/layout/grid-layout.md)中，元件在块轴上与网格区域的结束边缘对齐。

#### `flex-start`

同 `start` 表现一致。

#### `flex-end`

同 `end` 表现一致。

#### `baseline`

元件参与基线对齐。目前仅支持在[弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)中使用。

## 形式定义

| 初始值 | auto |
| 适用元素 | flex/grid/linear items |
| 是否支持继承 | 否 |
| 是否支持动画 | 否 |


## 形式语法

```
align-self = auto | center | start | end | flex-start | flex-end | baseline | stretch
```

## 与 Web 的区别

- 不支持 `normal`、`self-start` 和 `self-end`。

## 兼容性

**Compatibility Table**

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

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| align-self | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | 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;3 | Yes (2.16) | Yes (3.4) | Yes (2.16) | Yes (2.16) | Yes (2.16) | Yes |
| supported&#95;in&#95;flex&#95;layout.baseline | Yes (2.6) | Yes (3.4) | Yes (2.7) | Yes (2.7) | Yes (2.7) | Yes |
| supported&#95;in&#95;linear&#95;layout | Yes (2.2) | Yes (3.4) | Yes (2.2) | Yes (2.2) | Yes (2.2) | No |
| supported&#95;in&#95;linear&#95;layout.nested&#95;value&#95;1 | Yes (2.2) | Yes (3.4) | Yes (2.2) | Yes (2.2) | Yes (2.2) | Yes |
| supported&#95;in&#95;linear&#95;layout.nested&#95;value&#95;2 | Yes (2.16) | Yes (3.4) | Yes (2.16) | Yes (2.16) | Yes (2.16) | Yes |
| supported&#95;in&#95;linear&#95;layout.nested&#95;value&#95;3 | No | No | No | No | No | No |
| 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.16) | Yes (3.4) | Yes (2.16) | Yes (2.16) | Yes (2.16) | Yes |
| supported&#95;in&#95;grid&#95;layout.baseline | No | No | No | No | No | Yes |
| normal | No | No | No | No | No | Yes |

**`align-self`**

**Specifications:**

**`supported_in_flex_layout`**

Supported in Flexible Box Layout

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

**`supported_in_flex_layout.nested_value_1`**

<code>auto</code>, <code>stretch</code>, <code>flex-start</code>, <code>flex-end</code>, <code>center</code>

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

**`supported_in_flex_layout.nested_value_3`**

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

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

**`supported_in_flex_layout.baseline`**

<code>baseline</code>

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

**`supported_in_linear_layout`**

Supported in Linear Layout

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

**`supported_in_linear_layout.nested_value_1`**

<code>auto</code>, <code>flex-start</code>, <code>flex-end</code>, <code>center</code>

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

**`supported_in_linear_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/56-align-self.json)

**`supported_in_linear_layout.nested_value_3`**

<code>baseline</code> and <code>stretch</code>

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

**`supported_in_grid_layout`**

Supported in Grid Layout

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

**`supported_in_grid_layout.nested_value_1`**

<code>auto</code>, <code>stretch</code>, <code>flex-start</code>, <code>flex-end</code>, <code>center</code>

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/56-align-self.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/56-align-self.json)

**`supported_in_grid_layout.baseline`**

<code>baseline</code>

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

**`normal`**

<code>normal</code>

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

