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

# left

APISummary
## 介绍

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

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

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

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

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

## 使用示例

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

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

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

const Left = () => {
  const scrollViewStyle = {
    height: "100%",
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical" style={scrollViewStyle}>
      <view
        style={{
          width: "210px",
          height: "210px",
          border: "5px",
          borderColor: "black",
        }}
      >
        <view
          style={{
            position: "absolute",
            left: "80px",
            width: "50px",
            height: "50px",
            backgroundColor: "red",
          }}
        >
        </view>
        <view
          style={{
            position: "fixed",
            left: "155px",
            width: "50px",
            height: "50px",
            backgroundColor: "green",
          }}
        >
        </view>
        <view
          style={{
            position: "relative",
            left: "155px",
            width: "50px",
            height: "50px",
            backgroundColor: "yellow",
          }}
        >
        </view>
        <view
          style={{
            width: "50px",
            height: "50px",
            backgroundColor: "blue",
          }}
        >
        </view>
      </view>
    </scroll-view>
  );
};

root.render(<Left />);

```

v0.11.0



## 语法

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

/* Keyword value */
left: auto;

/* calc */
left: 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 |


## 形式语法

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

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

## 兼容性

**Compatibility Table**

**Query:** `css.properties.left`

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

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

**`left`**

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

**Specifications:**

