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

# background-clip

APISummary
## 介绍

`background-clip` 设置元件的背景 (目前只支持背景图片) 是否延伸到边框 (`border`)、内边距盒子 (`padding-box`)、内容盒子 (`content-box`) 下面。

如果没有设置 ([`background-image`](/next/zh/api/css/properties/background-image.md))，那么这个属性只有在边框 ([`border`](/next/zh/api/css/properties/border.md)) 被设置为非实心 (solid)、透明或半透明时才能看到视觉效果，否则，本属性产生的样式变化会被边框覆盖。

## 使用示例

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

**Entry:** `src/background-clip`
**Bundle:** `dist/background-clip.lynx.bundle`

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

const BackgroundClip = () => {
  const scrollViewStyle = {
    flexDirection: "column" as const,
    height: "2500px",
  };

  const fixedAreaStyle = {
    width: "100%",
    height: "100%",
    flexDirection: "column" as const,
  };

  return (
    <scroll-view className="root" scroll-orientation="vertical" style={scrollViewStyle}>
      <view className="fixed_area" style={fixedAreaStyle}>
        <text className="shared border-box"></text>
        <text className="shared padding-box"></text>
        <text className="shared content-box"></text>
        <text className="shared border-box radius"></text>
        <text className="shared padding-box radius"></text>
        <text className="shared content-box radius"></text>
        <text className="shared border-box radius2"></text>
        <text className="shared padding-box radius2"></text>
        <text className="shared content-box radius2"></text>
        <text className="shared border-area"></text>
        <text className="shared border-area radius"></text>
        <text className="shared border-area radius2"></text>
        <view className="container"></view>
        <view className="border-area-container"></view>
      </view>
    </scroll-view>
  );
};

root.render(<BackgroundClip />);

```

v0.11.0



## 语法

```css
background-clip: border-box;
background-clip: padding-box;
background-clip: content-box;
background-clip: border-area;

background-clip: border-box, content-box, padding-box, border-area;
```

### 取值

- **`border-box`** 

  背景延伸至边框外沿 (但是在边框下层)。

- **`padding-box`** 

  背景延伸至内边距 ([`padding`](/next/zh/api/css/properties/padding.md)) 外沿。不会绘制到边框处。

- **`content-box`**
  背景被裁剪至内容区 (content box) 外沿。

- **`border-area`**
  背景被裁切到边框绘制的区域，该区域会考虑 [`border-width`](/next/zh/api/css/properties/border-width.md) 的值。

- 默认值
  **border-box**

## 注意事项

当指定多个 `background-clip` 时，如果指定的 clip 的数量比 [`background-image`](/next/zh/api/css/properties/background-image.md) 的数量少时。第一个 clip 的值会作用在剩下的 [`background-image`](/next/zh/api/css/properties/background-image.md) 上。

:::warning
此属性对 `background-color` 不生效
:::

## 形式定义

| 初始值 | border-box |
| 适用元素 | all elements |
| 是否支持继承 | no |
| 是否支持动画 | no |


## 形式语法

```
<background-clip> = <box> | border-area

where

<box> = border-box | padding-box | content-box

```

## 与 Web 的区别

- 只支持关键字 `border-box`、`padding-box`、`content-box` 

  css 标准中还支持 `inherit`、`initial` 和 `unset`

- `border-area` 只考虑 `border-width` 不考虑 `border-style`

## 兼容性

**Compatibility Table**

**Query:** `css.properties.background-clip`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| background-clip | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| box | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |
| border-area | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Yes (3.7) | Unknown |

**`background-clip`**

**Specifications:**

**`box`**

<code>&lt;box&gt;</code>

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

**`border-area`**

<code>border-area</code>

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

- **Web — Compatibility unknown:** Passed through to the browser. Support for border-area depends on the browser.

