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

# flex-basis

APISummary
## 介绍

`flex-basis` 指定了弹性项目在**主轴**方向上的初始大小。这个属性就决定了弹性项目的边框区域（border area）的尺寸。
当一个元件同时被设置了 `flex-basis` (除值为 `auto` 外) 和 [`width`](/next/zh/api/css/properties/width.md) (或者在 [`flex-direction: column`](/next/zh/api/css/properties/flex-direction.md) 情况下设置了 [`height`](/next/zh/api/css/properties/height.md))，`flex-basis` 具有更高的优先级。

## 使用示例

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

**Entry:** `src/flex-basis`
**Bundle:** `dist/flex-basis.lynx.bundle`

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

const FlexBasis = () => {
  const itemStyle = {
    marginLeft: "5px",
    backgroundColor: "rgba(0,0,255,0.2)" as const,
    flexGrow: 1,
  };

  const autoStyle = {
    flexBasis: "auto" as const,
    backgroundColor: "rgba(255,0,200,0.2)" as const,
    flexGrow: 1,
  };

  const zeroPxStyle = {
    flexBasis: "0px",
    backgroundColor: "rgba(255,0,200,0.2)" as const,
    flexGrow: 1,
  };

  const px300Style = {
    flexBasis: "300px",
    backgroundColor: "rgba(255,0,200,0.2)" as const,
    flexGrow: 1,
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical">
      <view className="fixed_area">
        <view className="container">
          <view style={autoStyle}>
            <text>flex-basis:auto</text>
          </view>
          <view style={itemStyle}>
            <text>Item Two</text>
          </view>
          <view style={itemStyle}>
            <text>Item Three</text>
          </view>
        </view>

        <view className="container">
          <view style={zeroPxStyle}>
            <text>flex-basis:0px</text>
          </view>
          <view style={itemStyle}>
            <text>Item Two</text>
          </view>
          <view style={itemStyle}>
            <text>Item Three</text>
          </view>
        </view>

        <view className="container">
          <view style={px300Style}>
            <text>flex-basis:300px</text>
          </view>
          <view style={itemStyle}>
            <text>Item Two</text>
          </view>
          <view style={itemStyle}>
            <text>Item Three</text>
          </view>
        </view>
      </view>
    </scroll-view>
  );
};

root.render(<FlexBasis />);

```

v0.11.0



## 语法

```css
/* Specify <'width'> */
flex-basis: 10em;
flex-basis: 3px;
flex-basis: 50%;
flex-basis: auto;
```

### 取值

- `auto`

  **默认值**。参照自身的 [`width`](/next/zh/api/css/properties/width.md) 和 [`height`](/next/zh/api/css/properties/height.md) 属性。

- `<length>`

  绝对尺寸大小。

- `<percentage>`

  一个相对于其父弹性容器**主轴**内容区域（content area）的百分数。

## 形式定义

| 初始值 | `auto` |
| 适用元素 | flex items |
| 是否支持继承 | 否 |
| 是否支持动画 | yes |
| 百分比 | 相对于其父弹性容器主轴内容区域（content area） |


## 形式语法

```
flex-basis = auto | <length-percentage [0,∞]>

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

## 与 Web 的区别

- 值不受 [`box-sizing`](/next/zh/api/css/properties/box-sizing.md) 影响。

## 兼容性

**Compatibility Table**

**Query:** `css.properties.flex-basis`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| flex-basis | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| unsupported&#95;value&#95; | No | No | No | No | No | Yes |

**`flex-basis`**

<code>flex-basis</code>

**Specifications:**

**`unsupported_value_`**

<code>max-content</code>, <code>min-content</code>, <code>fit-content</code>

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/52-flex-basis.json)

