CSS3中background-clip实现图片裁切3种效果(代码实例 )


当前第2页 返回上一页

3、第三种裁切方式是以content为起点进行裁切content外的部分,所以background-clip: content-box;
所以index.css中添加代码如下:

1

2

3

4

5

6

7

8

9

.clip1{

    background-clip: border-box;

}

.clip2{

    background-clip: padding-box;

}

.clip3{

    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;

}

 

.clip1{

    background-clip: border-box;

}

.clip2{

    background-clip: padding-box;

}

.clip3{

    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>

运行结果如下:

实现效果.png

到此为止,我们就实现了全部的需求

总结:

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混合模式使用详解

如何解决CSS3 media不起作用的问题

详解CSS3实现弹性布局的方式

vs2010 如何支持CSS3

使用css过渡有哪些触发方式

transition-property属性怎么用

彻底理解css中视觉格式化模型(附示例)

css与CSS3的区别是什么

CSS3 animation属性怎么用

css怎么实现翻转效果

更多相关阅读请进入《CSS3》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...