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

# relative-center

APISummary
## 介绍

在[相对布局](/next/zh/guide/ui/layout/relative-layout.md)中，用于设置当前元件的居中对齐方式。

## 使用示例

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

**Entry:** `src/relative-center`
**Bundle:** `dist/relative-center.lynx.bundle`

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

const RelativeCenter = () => {
  const containerStyle = {
    display: "relative" as const,
  };

  const view1Style = {
    relativeCenter: "horizontal" as const,
    backgroundColor: "lightgreen" as const,
  };

  const view2Style = {
    relativeCenter: "vertical" as const,
    backgroundColor: "lightblue" as const,
  };

  const view3Style = {
    relativeCenter: "both" as const,
    backgroundColor: "yellow" as const,
  };

  const view4Style = {
    relativeCenter: "none" as const,
    backgroundColor: "pink" as const,
  };

  const textStyle = {
    fontSize: "70rpx" as const,
    fontWeight: "600" as const,
    textAlign: "center" as const,
  };

  return (
    <view className="container" style={containerStyle}>
      <view style={view1Style}>
        <text style={textStyle}>horizontal</text>
      </view>
      <view style={view2Style}>
        <text style={textStyle}>vertical</text>
      </view>
      <view style={view3Style}>
        <text style={textStyle}>both</text>
      </view>
      <view style={view4Style}>
        <text style={textStyle}>none</text>
      </view>
    </view>
  );
};

root.render(<RelativeCenter />);

```

v0.11.0



## 语法

```css
relative-center: none;
relative-center: both;
relative-center: vertical;
relative-center: horizontal;
```

### 取值

#### `none`

**默认值**。不居中。

#### `both`

垂直与水平都居中。

#### `vertical`

垂直居中。

#### `horizontal`

水平居中。

## 形式定义

| 初始值 | `none` |
| 适用元素 | relative items |
| 是否支持继承 | 否 |
| 是否支持动画 |  |


## 形式语法

```
relative-center = none | both | vertical | horizontal
```

## 与 Web 的区别

- Web 无此属性。

## 兼容性

**Compatibility Table**

**Query:** `css.properties.relative-center`

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/141-relative-center.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| relative-center | Yes (1.4) | Yes (3.4) | Yes (1.4) | Yes (1.4) | Yes (1.4) | No |

**`relative-center`**

Specifies that the current element is aligned with the bottom edge of the parent or sibling element corresponding to id.

**Specifications:**

