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

# height

APISummary
## 介绍

指定了一个元件的高度。
默认情况下，这个属性决定的是边框区域（border area）的高度，但如果将该元件的 [`box-sizing`](/next/zh/api/css/properties/box-sizing.md) 设置为 `content-box`，就转而设置内容区域（content area）的高度。

[`min-height`](/next/zh/api/css/properties/min-height.md) 和 [`max-height`](/next/zh/api/css/properties/max-height.md) 属性的优先级高于 `height`。

## 使用示例

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

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

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

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

  return (
    <scroll-view className="root" scroll-orientation="vertical" style={scrollViewStyle}>
      <view style={{ display: "linear", linearOrientation: "horizontal" }}>
        <text
          style={{
            height: "100px",
            border: "20px solid orange",
          }}
        >
          border-box
        </text>

        <text
          style={{
            height: "100px",
            border: "20px solid orange",
            boxSizing: "content-box",
          }}
        >
          content-box
        </text>
      </view>
    </scroll-view>
  );
};

root.render(<Height />);

```

v0.11.0



## 语法

```css
/* <length> values */
height: 300px;
height: 25em;

/* <percentage> value */
height: 75%;

/* Keyword values */
height: max-content;
height: fit-content;
height: fit-content(20em);
height: auto;
```

### 取值

- `auto`

  **默认值**。`lynx` 根据一些条件决定具体值。

- `<length>`

  [`<length>`](/next/zh/api/css/data-type/length.md) 将高度定义为一个绝对值。

- `<percentage>`

  [包含块](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Containing_block)高度的百分比 `<percentage>`。

- `max-content`

  元件内容固有的（intrinsic）合适高度。

- `fit-content`

  在内容最大高度及 [`fit-content`](/next/zh/api/css/data-type/fit-content.md) 定义值中取最小值。

## 形式定义

| 初始值 | `auto` |
| 适用元素 | 所有元件 |
| 是否支持继承 | 否 |
| 是否支持动画 | yes |
| 百分比 | The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to auto. A percentage height on the root element is relative to the initial containing block |


## 形式语法

```
height =
  auto                                      |
  <length-percentage [0,∞]>                 |
  max-content                               |
  fit-content( <length-percentage [0,∞]> )

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

## 与 Web 的区别

- `height` 默认决定的是边框区域（border area）的高度，而 Web 是 `content area`；
- 不支持 `min-content`；

## 兼容性

**Compatibility Table**

**Query:** `css.properties.height`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| height | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| max-content | Yes (1.6) | Yes (3.4) | Yes (1.6) | Yes (1.6) | Yes (1.6) | Yes |
| fit-content | Yes (2.0) | Yes (3.4) | Yes (2.0) | Yes (2.0) | Yes (2.0) | Yes |
| min-content | No | No | No | No | No | Yes |

**`height`**

**Specifications:**

**`max-content`**

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

**`fit-content`**

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

**`min-content`**

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

