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

# gap

APISummary
## 介绍

`gap` 属性是用来设置[弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)和[网格布局](/next/zh/guide/ui/layout/grid-layout.md)行与列之间的间隙（gutters），该属性是 [`row-gap`](/next/zh/api/css/properties/row-gap.md) 和 [`column-gap`](/next/zh/api/css/properties/column-gap.md) 的简写形式（`column-gap` 是可选的）。

假如 `column-gap` 缺失的话，则会被设置成跟 `row-gap` 一样的的值。`row-gap` 和 `column-gap` 都可以用 [`<length>`](/next/zh/api/css/data-type/length.md) 或者 [`<percentage>`](/next/zh/api/css/data-type/percentage.md) 来表示。

## 使用示例

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

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

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

const Gap = () => {
  const flexContainerStyle = {
    display: "flex" as const,
    flexWrap: "wrap" as const,
    gap: "15px",
    margin: "10px",
    padding: "5px",
    border: "1px solid #000",
    borderRadius: "4px",
    marginBottom: "100rpx" as const,
  };

  const gridContainerStyle = {
    display: "grid" as const,
    gap: "10px",
    gridTemplateColumns: "1fr 1fr 1fr",
    margin: "10px",
    padding: "5px",
    border: "1px solid #000",
    borderRadius: "4px",
  };

  const titleStyle = {
    fontSize: "50rpx" as const,
    alignSelf: "center" as const,
    fontWeight: "900" as const,
    color: "linear-gradient(to right, rgb(255,53,26), rgb(0,235,235))" as const,
  };

  return (
    <>
      <text style={titleStyle}>using gap in flex layout</text>
      <view style={flexContainerStyle}>
        <text className="item">ONE</text>
        <text className="item">TWO</text>
        <text className="item">THREE</text>
        <text className="item">FOUR</text>
        <text className="item">FIVE</text>
        <text className="item">SIX</text>
        <text className="item">SEVEN</text>
        <text className="item">EIGHT</text>
        <text className="item">NINE</text>
        <text className="item">TEN</text>
      </view>

      <text style={titleStyle}>using gap in grid layout</text>
      <view style={gridContainerStyle}>
        <text className="item2">ONE</text>
        <text className="item2">TWO</text>
        <text className="item2">THREE</text>
        <text className="item2">FOUR</text>
        <text className="item2">FIVE</text>
        <text className="item2">SIX</text>
        <text className="item2">SEVEN</text>
        <text className="item2">EIGHT</text>
        <text className="item2">NINE</text>
        <text className="item2">TEN</text>
      </view>
    </>
  );
};

root.render(<Gap />);

```

v0.11.0



## 语法

```css
/* One <length> value */
gap: 20px;
gap: 1em;

/* One <percentage> value */
gap: 16%;
gap: 100%;

/* Two <length> values */
gap: 20px 10px;
gap: 1em 0.5em;

/* One or two <percentage> values */
gap: 16% 100%;
gap: 21px 82%;

/* calc() values */
gap: calc(10% + 20px);
gap: calc(20px + 10%) calc(10% - 5px);
```

### 取值

- `<length>`

  [弹性布局](/next/zh/guide/ui/layout/flexible-box-layout.md)或[网格布局](/next/zh/guide/ui/layout/grid-layout.md)行与列之间的间隙宽度。

- `<percentage>`

  行与列之间直接的间隙宽度，相对容器自身 content area 对应轴尺寸的百分比。比如说，[`row-gap`](/next/zh/api/css/properties/row-gap.md) 使用 `percentage` 时，是相对于自身 `content area` **竖向大小**的百分比。

## 形式定义

| 初始值 | as each of the properties of the shorthand: 
- `row-gap: 0`
- `column-gap: 0` |
| 适用元素 | 弹性容器和网格容器 |
| 是否支持继承 | 否 |
| 是否支持动画 |  |
| 百分比 | refer to corresponding dimension of the content area(e.g.,`row-gap` refer to column axis size) |


## 形式语法

```
gap =
  <'row-gap'> <'column-gap'>?

<row-gap> = <length-percentage [0,∞]>

<column-gap> = <length-percentage [0,∞]>

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

## 兼容性

**Compatibility Table**

**Query:** `css.properties.gap`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| gap | Yes (2.14) | Yes (3.4) | Yes (2.14) | Yes (2.14) | Yes (2.14) | Yes |
| Flex | Yes (2.14) | Yes (3.4) | Yes (2.14) | Yes (2.14) | Yes (2.14) | Yes |
| Grid | Yes (2.14) | Yes (3.4) | Yes (2.14) | Yes (2.14) | Yes (2.14) | Yes |

**`gap`**

**Specifications:**

**`Flex`**

Supported in Flexible Box Layout

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

**`Grid`**

Supported in Grid Layout

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

