background-clip属性
background-clip
(背景裁剪)设置元素的背景(背景图片或颜色)是否延伸到边框、内边距盒子、内容盒子下面。
值 | 说明 |
---|
border-box | 默认值。背景绘制在边框方框内(剪切成边框方框)。 |
padding-box | 背景绘制在衬距方框内(剪切成衬距方框)。 |
content-box | 背景绘制在内容方框内(剪切成内容方框)。 |
background-clip: text;-webkit-background-clip: text;color: transparent; | 以文字的范围来裁剪背景图片 |
border-box
<style>
.div1{
width: 346px;
height: 346px;
padding: 10px;
background-color: rgb(0, 255, 255);
background-clip: border-box;
border: 10px dashed rgb(78, 164, 80);
}
</style>
</head>
<body>
<div class="div1">
<img src="./src/assets/hmbb.png" alt="">
</div>
</body>
content-box
<style>
.div1{
width: 346px;
height: 346px;
padding: 10px;
background-color: rgb(0, 255, 255);
background-clip: content-box;
border: 10px dashed rgb(78, 164, 80);
}
</style>
</head>
<body>
<div class="div1">
<img src="./src/assets/hmbb.png" alt="">
</div>
</body>
padding-box
<style>
.div1{
width: 346px;
height: 346px;
padding: 10px;
background-color: rgb(0, 255, 255);
background-clip: padding-box;
border: 10px dashed rgb(78, 164, 80);
}
</style>
</head>
<body>
<div class="div1">
<img src="./src/assets/hmbb.png" alt="">
</div>
</body>
background-clip: text;
<style>
p{
color: transparent;
-webkit-background-clip: text;
background-clip: text;
line-height: 30px;
background-image: url(./src/assets/hmbb.png);
}
</style>
</head>
<body>
<p>这是一段以文字的范围来裁剪背景图片</p>
</body>
<style>
p{
color: transparent;
-webkit-background-clip: text;
background-clip: text;
line-height: 30px;
background-image: linear-gradient(to right,red,orange,yellow,green,cyan,blue,purple);
}
</style>
</head>
<body>
<p>这是一段用线性渐变实现的彩虹字体哦</p>
</body>
background-origin属性
值 | 描述 |
---|
padding-box | 背景图像填充框的相对位置 |
border-box | 背景图像边界框的相对位置 |
content-box | 背景图像的相对位置的内容框 |