主题
  • 默认模式
  • 浅蓝色模式
  • 淡绿色模式
  • 深夜模式

定义和用法

background-clip是 CSS 中用于控制背景绘制区域的属性,它决定了背景(颜色或图片)应该延伸到元素的哪个区域。

background-clip常用于创建特殊视觉效果,如文字填充效果或控制背景在边框下的显示方式。

默认值: border-box
继承性:
可动画性: 否。请参阅:可动画属性
版本: CSS3
JavaScript 语法: object.style.backgroundClip="content-box"

常用的实例

接下来通过多个实例演示background-clip属性的用法,来深化您对background-clip属性的理解。

实例代码 运行代码
复制
/* 默认值 - 背景延伸到边框 */
.example1 {
    background-clip: border-box;
    border: 10px dotted rgba(0,0,0,0.5);
    padding: 20px;
}

/* 背景只延伸到内边距 */
.example2 {
    background-clip: padding-box;
    border: 10px dotted rgba(0,0,0,0.5);
    padding: 20px;
}

/* 背景只在内容区显示 */
.example3 {
    background-clip: content-box;
    border: 10px dotted rgba(0,0,0,0.5);
    padding: 20px;
}

/* 文字填充背景效果 */
.example4 {
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-image: linear-gradient(to right, red, blue);
}

CSS 语法

background-clip: border-box|padding-box|content-box|text;

属性值

描述
border-box 默认,背景延伸到边框外边缘(在边框下层绘制)。
padding-box 背景延伸到内边距(padding)外边缘,边框下不绘制背景。
content-box 背景仅在内容区域绘制,内边距区域不绘制。
text 背景被裁剪为文字的前景色(需要配合-webkit-text-fill-color: transparent使用)。

浏览器支持

表中的数字指定了完全支持background-clip属性的第一个浏览器版本。

Chrome 浏览器 EDGE 浏览器 Firefox 浏览器 Safari 浏览器 Opera 浏览器
Chrome Edge Firefox Safari Opera
4.0 9.0 4.0 3.0 10.5

相关页面

CSS 教程:CSS 背景



评论区 0
发表评论
教程介绍
CSS 参考手册全面涵盖选择器、盒模型,文本属性等,助您快速检索 CSS 使用方法。
95 章节
102 阅读
0 评论
教程目录

CSS 参考手册

CSS 属性(字母排序) CSS 属性(功能排序) CSS 浏览器支持 CSS 选择器 CSS 函数 CSS 可动画性 CSS Web安全字体 CSS 单位 CSS 颜色 CSS 颜色值

CSS 属性

align-content align-items align-self all animation animation-delay animation-direction animation-duration animation-fill-mode animation-iteration-count animation-name animation-play-state animation-timing-function aspect-ratio backdrop-filter backface-visibility background background-attachment background-blend-mode background-clip background-color background-image background-origin background-position background-position-x background-position-y background-repeat background-size block-size border border-block border-block-color border-block-end border-block-end-color border-block-end-style border-block-end-width border-block-start border-block-start-color border-block-start-style border-block-start-width border-block-style border-block-width border-bottom border-bottom-color border-bottom-left-radius border-bottom-right-radius border-bottom-style border-bottom-width border-collapse border-color border-end-end-radius border-end-start-radius border-image border-image-outset border-image-repeat border-image-slice border-image-source border-image-width border-inline border-inline-color border-inline-end border-inline-end-color border-inline-end-style border-inline-end-width border-inline-start border-inline-start-color border-inline-start-style border-inline-start-width border-inline-style border-inline-width border-left border-left-color border-left-style border-left-width border-radius border-right border-right-color border-right-style border-right-width border-spacing border-start-end-radius border-start-start-radius border-top-left-radius border-top-right-radius border-top-style