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

APISummary
## 介绍

用于设置[相对布局](/next/zh/guide/ui/layout/relative-layout.md)中同级元件的编号。`-1` 和 `0` 是特殊值。`-1` 是默认值，代表当前元件不会被视为同级元件的对齐参考标准。不能使用 `0` 作为元件的 id，否则有不符合预期的表现。

## 使用示例

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

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

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

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

  const view1Style = {
    relativeId: "1",
    backgroundColor: "lightgreen",
  };

  const view2Style = {
    relativeRightOf: "1",
    relativeId: "2",
    backgroundColor: "lightblue",
  };

  const view3Style = {
    relativeId: "3",
    relativeCenter: "vertical" as const,
    backgroundColor: "yellow",
  };

  const view4Style = {
    relativeRightOf: "3",
    relativeId: "4",
    relativeCenter: "vertical" as const,
    backgroundColor: "pink",
  };

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

  return (
    <view className="container" style={containerStyle}>
      <view style={view1Style}>
        <text style={textStyle}>relative-id: 1</text>
      </view>
      <view style={view2Style}>
        <text style={textStyle}>relative-id: 2</text>
      </view>
      <view style={view3Style}>
        <text style={textStyle}>relative-id: 3</text>
      </view>
      <view style={view4Style}>
        <text style={textStyle}>relative-id: 4</text>
      </view>
    </view>
  );
};

root.render(<RelativeId />);

```

v0.11.0



## 语法

```css
relative-id: 1;
relative-id: 2;
```

### 取值

#### `<number>`

`int` 值。表示当前元件的编号。**默认值**为 `-1`。`-1` 和 `0` 是特殊值。`-1` 是默认值，代表当前元件不会被视为同级元件的对齐参考标准。不能使用 `0` 作为元件的 id，否则有不符合预期的表现。

## 形式定义

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


## 形式语法

```
relative-id = <integer [1,∞]>
```

## 与 Web 的区别

- Web 无此属性。

## 兼容性

**Compatibility Table**

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

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

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

**`relative-id`**

Used to set the number of sibling elements in the relative layout.

**Specifications:**

