当前第2页 返回上一页
3、第三种裁切方式是以content为起点进行裁切content外的部分,所以background-clip: content-box;
所以index.css中添加代码如下:
1 2 3 4 5 6 7 8 9 | .clip 1 {
background- clip : border-box;
}
.clip 2 {
background- clip : padding-box;
}
.clip 3 {
background- clip : content-box;
}
|
到此为止,index.css的全部内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | .container *{
padding : 0 ;
margin : 0 ;
}
.photo {
width : 420px ;
height : 420px ;
border-width : 20px ;
border-style : dashed ;
padding : 20px ;
font-weight : bold ;
color : #fff ;
background : #ccc url (../images/zhm.png) no-repeat ;
border-color : indianred;
background-origin: border-box;
}
.clip 1 {
background- clip : border-box;
}
.clip 2 {
background- clip : padding-box;
}
.clip 3 {
background- clip : content-box;
}
|
然后将index.css引入index.html中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <!DOCTYPE html>
< html >
< head >
< meta charset = "utf-8" >
< title >背景裁切案例演示</ title >
< link rel = "stylesheet" href = "css/index.css" />
</ head >
< body >
< div class = "container" >
< h4 >裁切效果一</ h4 >
< div class = "photo clip1" >
< div class = "content" >周慧敏,微微一笑,很倾城</ div >
</ div >
< h4 >裁切效果二</ h4 >
< div class = "photo clip2" >
< div class = "content" >周慧敏,微微一笑,很倾城</ div >
</ div >
< h4 >裁切效果三</ h4 >
< div class = "photo clip3" >
< div class = "content" >周慧敏,微微一笑,很倾城</ div >
</ div >
</ div >
</ body >
</ html >
|
运行结果如下:

到此为止,我们就实现了全部的需求
总结:
1、学习了背景裁切的3种方式,语法格式是
background-clip: border-box | padding-box | content-box | no-clip
border-box:表示以边框为起点,裁切边框外的部分
padding-box:表示以padding为起点,裁切padding外的部分
content-box:表示以content为起点,裁切content外的部分
以上就是CSS3中background-clip实现图片裁切3种效果(代码实例 )的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
CSS3新增的伪类有哪些
flex作用于box容器上的属性介绍
CSS3中background-orgin实现带相框照片显示效果-案例解析(代码实例 )
html5/CSS3 网页加载进度条的实现,下载进度条等经典案例
CSS3 教程
关于老式浏览器兼容html5和CSS3的问题详解
word-wrap属性怎么用
CSS3如何实现图片木桶布局?(附代码)
CSS3有哪些新特性
CSS3动画如何停止
更多相关阅读请进入《CSS3》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » CSS3中background-clip实现图片裁切3种效果(代码实例 )