Style backgroundClip 属性 详解
css3基础 2023-07-30 01:08:472小码哥的IT人生shichen
Style backgroundClip 属性
定义和用法
backgroundClip
属性设置或返回背景的绘制区域。
另请参阅:
HTML 样式:background 属性
CSS 教程:CSS 背景
CSS 参考手册:background-clip 属性
实例
指定背景的绘制区域:
document.getElementById("myDIV").style.backgroundClip = "content-box";
完整实例【亲自试一试】:
<!DOCTYPE html> <html> <head> <style> #myDIV { width: 300px; height: 300px; padding: 50px; background-color: coral; background-clip: border-box; color: white; border: 5px dotted lightgrey; } </style> </head> <body> <p>请点击“试一试”按钮,将 DIV 元素的 background-clip 属性设置为 “content-box”:</p> <button onclick="myFunction()">试一试</button> <div id="myDIV"> 大熊猫(学名:Ailuropoda melanoleuca):属于熊科、大熊猫属的哺乳动物。仅有二个亚种。雄性个体稍大于雌性。体型肥硕似熊、丰腴富态,头圆尾短,头躯长1.2-1.8米,尾长10-12厘米。体重80-120千克,最重可达180千克,体色为黑白两色,脸颊圆,有很大的“黑眼圈”,标志性的内八字的行走方式,也有解剖刀般锋利的爪子。大熊猫皮肤厚,最厚处可达10毫米。黑白相间的外表,有利于隐蔽在密林的树上和积雪的地面而不易被天敌发现。生活在海拔2600-3500米的茂密竹林里,那里常年空气稀薄,云雾缭绕,气温低于20℃。有充足的竹子,地形和水源的分布利于该物种建巢藏身和哺育幼仔。 </div> <script> function myFunction() { document.getElementById("myDIV").style.backgroundClip = "content-box"; } </script> </body> </html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html
语法
返回 backgroundClip 属性:
object.style.backgroundClip
设置 backgroundClip 属性:
object.style.backgroundClip = "border-box|padding-box|content-box|initial|inherit"
属性值
值 | 描述 |
---|---|
border-box | 默认值。背景被裁剪到边框盒(border box)。 |
padding-box | 背景被裁剪到内边距框。 |
content-box | 背景被裁剪到内容框。 |
initial | 将此属性设置为其默认值。请参阅 initial。 |
inherit | 从其父元素继承此属性。请参阅 inherit。 |
技术细节
默认值: | border-box |
---|---|
返回值: | 字符串,表示元素的 background-clip 属性。 |
CSS 版本: | CSS3 |
浏览器支持
backgroundClip
是 CSS3 (1999) 特性。
所有浏览器都完全支持它:
Chrome | Edge | Firefox | Safari | Opera | IE |
---|---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera | IE |
支持 | 支持 | 支持 | 支持 | 支持 | 11 |