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

# right

APISummary
## 介绍

`right` 属性定义了定位元件的右外边距边界与其包含块右边界之间的偏移，非定位元件设置此属性无效。定位元件参考 [position 属性](/next/zh/api/css/properties/position.md)。

`right` 的效果取决于元件的 `position` 属性：

- 当 `position` 设置为 `absolute` 或 `fixed` 时，`right` 属性指定了定位元件右外边距边界与其包含块右边界之间的偏移。

- 当 `position` 设置为 `relative` 时，`right` 属性指定了元件的右边界离开其正常位置的偏移。

当 `left` 和 `right` 同时指定时，元件的位置会被重复指定。当容器是从左到右时，`left` 的值会被优先设定；当容器是从右到左时，`right` 的值会被优先设定。

## 使用示例

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

**Entry:** `src/right`
**Bundle:** `dist/right.lynx.bundle`

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

const Right = () => {
  const containerStyle = {
    width: "210px",
    height: "210px",
    border: "5px",
    borderColor: "black",
  };

  const firstBoxStyle = {
    position: "absolute" as const,
    right: "80px",
    width: "50px",
    height: "50px",
    backgroundColor: "red",
  };

  const secondBoxStyle = {
    position: "fixed" as const,
    right: "155px",
    width: "50px",
    height: "50px",
    backgroundColor: "green",
  };

  const thirdBoxStyle = {
    position: "relative" as const,
    right: "40px",
    width: "50px",
    height: "50px",
    backgroundColor: "yellow",
  };

  const fourthBoxStyle = {
    width: "50px",
    height: "50px",
    backgroundColor: "blue",
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view style={containerStyle}>
        <view style={firstBoxStyle}></view>
        <view style={secondBoxStyle}></view>
        <view style={thirdBoxStyle}></view>
        <view style={fourthBoxStyle}></view>
      </view>
    </scroll-view>
  );
};

root.render(<Right />);

```

v0.11.0



## 语法

```css
/* <length> values */
right: 3px;
right: 2rpx;
right: 2.4em;
right: 3rem;

right: 10%;

/* Keyword value */
right: auto;

/* calc */
right: calc(1px + 1px);
```

### 取值

#### `auto`

**默认值**。

#### `<length>`

可以是负的，正的或者 null [`<length>`](/next/zh/api/css/data-type/length.md) 表示：

- 对于绝对定位的元件，元件右外边距边界与其包含块右边界之间的偏移。
- 对于相对定位定位的元件，元件的右边界离开其正常位置的偏移。

#### `<percentage>`

使用外层元件的容纳区块宽度（the containing block's width）的百分比定义宽度。

## 形式定义

| 初始值 | auto |
| 适用元素 | 所有元件 |
| 是否支持继承 | 否 |
| 是否支持动画 | yes |
| 百分比 | refer to the width of the containing block |


## 形式语法

```
right =
  auto                 |
  <length-percentage>  |

<length-percentage> =
  <length>      |
  <percentage>
```

## 兼容性

**Compatibility Table**

**Query:** `css.properties.right`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| right | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |

**`right`**

participates in setting the horizontal position of a positioned element. It has no effect on non-positioned elements.

**Specifications:**

