我们来看看background有哪些属性:
background : [background-image] [background-origin] [background-clip] [background-repeat] [background-size] [background-attachment] [background-position]
多个背景图片的url之间使用逗号隔开即可,如果有多个背景图片,而其他属性只有一个(例如background-repeat只有一个),那么所有背景图片都应用该属性值。
下面我们就看一个例子吧:
这里我们要使用5张图片作为一个p容器的背景,我们来看一下代码:
HTML代码:
<p class="p1"> <a href="#" title="脚本之家">脚本之家</a> </p>
CSS代码:
.p1{ margin:50px auto; width:700px; height:450px; border:10px dashed #ff00ff; background-image:url(images/1.jpg),url(images/2.jpg),url(images/3.jpg),url(images/4.jpg),url(images/5.jpg); background-repeat:no-repeat,no-repeat,no-repeat,no-repeat,no-repeat; background-position:top left,top right,bottom left,bottom right,center center; }
效果如下图:
在上面的代码中有这一句:
background-repeat:no-repeat;
写一个值就行了,效果是完全一样的。
当然上面设置背景图片的各个属性时是分开写的,那么我们也可以把背景图片的各个属性写在一块,这时的CSS代码如下:
.p1{ ... background:url(images/1.jpg) no-repeat top left, url(images/2.jpg) no-repeat top right, url(images/3.jpg) no-repeat bottom left, url(images/4.jpg) no-repeat bottom right, url(images/5.jpg) no-repeat center center; ... }
评论前必须登录!
注册