百科狗-知识改变命运!

background-clip - 背景图像外裁剪的区域 - css 背景颜色

百变鹏仔2年前 (2023-11-21)阅读数 21#技术干货
文章标签边框

background-clip

版本:CSS3

background-clip 设置元素的背景(背景图片或颜色)是否延伸到边框、内边距盒子、内容盒子下面。

示例

/* keyword values */
background-clip: border-box;
background-clip: padding-box;
background-clip: content-box;
background-clip: text;

/* global values */
background-clip: inherit;
background-clip: initial;
background-clip: unset;

如果没有设置背景图片(background-image)或背景颜色(background-color),那么这个属性只有在边框(border)被设置为非固实(soild)、透明或半透明时才能看到视觉效果(与border-styleborder-image有关),否则,本属性产生的样式变化会被边框覆盖。

background-clip - 背景图像外裁剪的区域 - css 背景颜色

浏览器支持

IE9以上版本的浏览器都支持background-clip

语法:

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

取值:

  • border-box:背景延伸至边框外沿(但是在边框下层)。
  • padding-box:背景延伸至内边距(padding)外沿。不会绘制到边框处。
  • content-box:背景被裁剪至内容区(content box)外沿。
  • text:从前景内容的形状(比如文字)作为裁剪区域向外裁剪。
默认值border-box
适用于所有元素
继承性
动画性
计算值指定值

例子

//html

the background extends behind the border.

the background extends to the inside edge of the border.

the background extends only to the edge of the content box.

the background is clipped to the foreground text.

//CSS p { border: .8em darkviolet; border-style: dotted double; margin: 1em 0; padding: 1.4em; background: linear-gradient(60deg, red, yellow, red, yellow, red); font: 900 1.2em sans-serif; text-decoration: underline; } .border-box { background-clip: border-box; } .padding-box { background-clip: padding-box; } .content-box { background-clip: content-box; } .text { background-clip: text; -webkit-background-clip: text; color: rgba(0,0,0,.2); }

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)
{if $zbp->Config('yd1125')->foot}