CSS3中background-image实现多背景图片(代码实例)


当前第2页 返回上一页

所以index.css中添加代码如下:

1

2

3

4

5

6

7

8

9

10

11

.bg1 {

    background-position: left top, 350px 0, 700px 0;

}

 

.bg2 {

    background-position: left top, 300px 0, 700px 0;

}

 

.bg3 {

    background-position: left top, 400px 0, 700px 0;

}

到此为止,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

27

28

29

30

.container *{

    padding:0;

    margin:0;

}

h4{

    text-align: center;

}

.demo {

    width: 1000px;

    height: 300px;

    border: 1px solid #999;

    background-image: url(../images/gtl1.jpg),

        url(../images/gtl2.jpg),

        url(../images/gtl3.jpg);

 

    background-repeat: no-repeat, no-repeat, no-repeat;

    margin: 0 auto 20px auto;

}

 

.bg1 {

    background-position: left top, 350px 0, 700px 0;

}

 

.bg2 {

    background-position: left top, 300px 0, 700px 0;

}

 

.bg3 {

    background-position: left top, 400px 0, 700px 0;

}

然后将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

<!DOCTYPE html>

<html>

 

<head>

    <meta charset="utf-8">

    <title>多重背景</title>

    <link rel="stylesheet" href="css/index.css" />

</head>

 

<body>

    <div class="container">

        <h4>效果1</h4>

        <div class="demo bg1"></div>

        <h4>效果2</h4>

        <div class="demo bg2"></div>

        <h4>效果3</h4>

        <div class="demo bg3"></div>

    </div>

 

</body>

 

</html>

运行效果如下

实现效果.png

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

总结:

1、background-image可以设置多背景图片,语法格式如下:

background-image: url(图片地址1),

url(图片地址2),

url(图片地址3).......还可以N个;

2、如果设置了多背景图片,那么在设置 background-repeat和 background-position的时候要注意顺序和图片设置的顺序一样,如果设置成一个,那么说明所有的背景图片都是一样的设置

以上就是CSS3中background-image实现多背景图片(代码实例)的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

使用modernizr探测html5/CSS3新特性的示例代码分享

CSS3字体可以模糊吗

css <basic-shape>的基本形状函数有哪些?如何使用?

perspective-origin属性怎么用

CSS3 appearance属性怎么用?

transform-origin属性怎么用

CSS3新特性有哪些

CSS3实现条状百分比效果

CSS3有哪些新特性

html5和CSS3 实现灵动画的切换效果

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




打赏

取消

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

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

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

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

评论

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