Home > Article > Web Front-end > Implementation of multiple backgrounds by sharing CSS3 examples (Multiple backgrounds)_CSS/HTML
CSS3的诞生为我们解决了这一问题,在CSS3里,通过background-image或者background可以为一个容器设置多张背景图像,也就是说可以把不同背景图象只放到一个块元素里。
首先我们来看一下语法吧:
background : [background-image] | [background-origin] | [background-clip] | [background-repeat] | [background-size] | [background-attachment] | [background-position]
多个背景图片的url之间使用逗号隔开即可,如果有多个背景图片,而其他属性只有一个(例如background-repeat只有一个),那么所有背景图片都应用该属性值。
下面我们就看一个例子吧:
这里我们要使用5张图片作为一个div容器的背景,我们来看一下代码:
HTML代码:
CSS代码:
效果如下图:
In the above code there is this sentence:
Just write a value, the effect is exactly the same.
Of course, when setting the various attributes of the background image above, they are written separately, so we can also write the various attributes of the background image together. In this case, the CSS code is as follows:
Oh, that’s how CSS3 multiple backgrounds work. It’s very simple. The complete source code and examples are provided below, which can be used as a reference.