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

# vertical-align

APISummary
## 介绍

用于指定内联元件（`text` 子元件）的垂直对齐方式。

## 使用示例

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

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

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

const VerticalAlign = () => {
  const containerStyle = {
    display: "linear" as const,
  };

  const titleStyle = {
    backgroundColor: "white",
  };

  const orangeContainerStyle = {
    lineHeight: "100px",
    backgroundColor: "orange",
  };

  const tomatoContainerStyle = {
    lineHeight: "100px",
    backgroundColor: "tomato",
  };

  const titleTextStyle = {
    fontSize: "25px",
  };

  const imageStyle = (align: string) => ({
    width: "20px",
    height: "20px",
    verticalAlign: align,
  });

  const textStyle = (align: string) => ({
    verticalAlign: align,
  });

  const viewStyle = (align: string) => ({
    width: "20px",
    height: "20px",
    backgroundColor: "yellow",
    verticalAlign: align,
  });

  return (
    <view className="intro" style={containerStyle} lynx-test-tag="container">
      <text style={titleStyle}>
        set vertical-align: middle,center,top,bottom,text-top,text-bottom,super,baseline,sub
      </text>
      <text style={orangeContainerStyle}>
        <text style={titleTextStyle}>inline-image:</text>

        <image src={playImage} style={imageStyle("middle")}></image>
        <image src={playImage} style={imageStyle("center")}></image>
        <image src={playImage} style={imageStyle("top")}></image>
        <image src={playImage} style={imageStyle("bottom")}></image>
        <image src={playImage} style={imageStyle("text-top")}></image>
        <image src={playImage} style={imageStyle("text-bottom")}></image>
        <image src={playImage} style={imageStyle("super")}></image>
        <image src={playImage} style={imageStyle("baseline")}></image>
        <image src={playImage} style={imageStyle("sub")}></image>
      </text>
      <text style={tomatoContainerStyle}>
        <text style={titleTextStyle}>inline-text:</text>
        <text style={textStyle("middle")}>xx</text>
        <text style={textStyle("center")}>xx</text>
        <text style={textStyle("top")}>xx</text>
        <text style={textStyle("bottom")}>xx</text>
        <text style={textStyle("text-top")}>xx</text>
        <text style={textStyle("text-bottom")}>xx</text>
        <text style={textStyle("super")}>xx</text>
        <text style={textStyle("baseline")}>xx</text>
        <text style={textStyle("sub")}>xx</text>
      </text>
      <text style={orangeContainerStyle}>
        <text style={titleTextStyle}>inline-view</text>
        <view style={viewStyle("middle")}></view>
        <view style={viewStyle("center")}></view>
        <view style={viewStyle("top")}></view>
        <view style={viewStyle("bottom")}></view>
        <view style={viewStyle("text-top")}></view>
        <view style={viewStyle("text-bottom")}></view>
        <view style={viewStyle("super")}></view>
        <view style={viewStyle("baseline")}></view>
        <view style={viewStyle("sub")}></view>
      </text>
    </view>
  );
};

root.render(<VerticalAlign />);

```

v0.11.0



## 语法

```css
vertical-align: 10px;
vertical-align: 50%;
vertical-align: baseline;
vertical-align: middle;
vertical-align: center;
vertical-align: top;
vertical-align: bottom;
vertical-align: text-top;
vertical-align: text-bottom;
vertical-align: super;
vertical-align: sub;
```

### 取值

- `<length>`
  支持 Lynx 中 [`length`](/next/zh/api/css/data-type/length.md) 写法，在垂直方向偏移 length 值，支持负值。

- `<percent>`
  只有设置 [`line-height`](/next/zh/api/css/properties/line-height.md) 值的百分比。

- `baseline`
  基线对齐。

- `middle`
  取所有 text 的最大 x-height，元件高度的一半对齐最大 x-height 的一半。

- `center`
  元件高度的一半对齐行高的一半。

- `top`
  元件的最顶部对齐行高最顶部。

- `bottom`
  元件最底部对齐行高最底部。

- `text-top`
  取所有 text 的最大 ascent，元件最顶部对齐最大 ascent。

- `text-bottom`
  取所有 text 的最大 descent，元件最底部对齐最大 descent。

- `super`
  向上偏移当前元件高度的 10%。

- `sub`
  向下偏移当前元件高度的 10%。

- 默认值
  **baseline**

## 形式定义

| 初始值 | baseline |
| 适用元素 | 嵌套 text、嵌套 image、嵌套 view |
| 是否支持继承 | no |
| 是否支持动画 | no |


## 形式语法

```
<length> | <percent> | baseline | middle | center | top | bottom | text-top | text-bottom | super | sub
```

## 与 Web 的区别

- [mdn:vertical-align](https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align)

## 注意事项

- `text` 元件嵌套 `view` 时默认文本基线对齐 `view` 的底部，需在 `view` 上显式设置 `vertical-align-baseline` 才能保证文本基线对齐 `view` 中文本基线。

## 兼容性

**Compatibility Table**

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

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| vertical-align | Yes (2.6) | Yes (3.4) | Yes (2.6) | Yes (2.6) | Yes (2.6) | Yes |

**`vertical-align`**

**Specifications:**

