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

# max-height

APISummary
## 介绍

设置元件的最大高度。它可以阻止 [`height`](/next/zh/api/css/properties/height.md) 属性的应用值大于 `max-height` 的值。
`max-height` 的值会覆盖 [`height`](/next/zh/api/css/properties/height.md) 和 [`min-height`](/next/zh/api/css/properties/min-height.md)。

## 使用示例

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

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

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

const MaxHeight = () => {
  const containerStyle = {
    display: "linear" as const,
    linearDirection: "row" as const,
  };

  const firstBoxStyle = {
    height: "300px",
    backgroundColor: "green",
    width: "100px",
  };

  const secondBoxStyle = {
    height: "400px",
    backgroundColor: "yellow",
    width: "100px",
    maxHeight: "300px",
  };

  const thirdBoxStyle = {
    height: "300px",
    backgroundColor: "blue",
    width: "100px",
    minHeight: "400px",
    maxHeight: "200px",
  };

  return (
    <view className="intro" style={containerStyle}>
      <view style={firstBoxStyle}>
        <text>height: 300px</text>
      </view>
      <view style={secondBoxStyle}>
        <text>height: 400px; max-height: 300px</text>
      </view>
      <view style={thirdBoxStyle}>
        <text>height: 300px; min-height: 400px; max-height: 200px</text>
      </view>
    </view>
  );
};

root.render(<MaxHeight />);

```

v0.11.0



## 语法

```css
/* <length> */
max-height: 120px;
max-height: 10em;

/* <percentage> */
max-height: 75%;
```

### 取值

默认盒子高度没有限制。

#### `<length>`

[`<length>`](/next/zh/api/css/data-type/length.md) 定义了一个确定值。

#### `<percentage>`

定义作为包含区块高度百分比的 `max-height`。

## 形式定义

| 初始值 | 盒子高度没有限制 |
| 适用元素 | 所有元件 |
| 是否支持继承 | 否 |
| 是否支持动画 | yes |
| 百分比 | The percentage is calculated with respect to the height of the generated box's containing block |


## 形式语法

```
max-height = <length-percentage [0,∞]>

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

## 与 Web 的区别

[mdn: max-height](https://developer.mozilla.org/en-US/docs/Web/CSS/max-height)

1. 不支持 `none`，`max-content`，`min-content`，`fit-content`。
2. 在 Lynx 中 `max-height` 会覆盖 [`min-height`](/next/zh/api/css/properties/min-height.md)。
3. 在 Lynx 中，如果指定的 `max-height` 小于 `min-height`，则 `min-height` 会被忽略。

## 兼容性

**Compatibility Table**

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

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

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

**`max-height`**

sets the maximum height of an element.

**Specifications:**

