html可以加多个背景图片吗

  • 时间:
  • 来源:网络

   

html可以加多个背景图片。html中,可以通过background-image或者background为一个容器设置多张背景图像,即把不同背景图象只放到一个块元素里;语法“background:url(图片地址),url(地址)..;”。


本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

html中,可以通过background-image或者background为一个容器设置多张背景图像,也就是说可以把不同背景图象只放到一个块元素里。

首先我们来看一下语法吧:

background : [background-image] | [background-origin] | [background-clip] | [background-repeat] | [background-size] | [background-attachment] | [background-position]

多个背景图片的url之间使用逗号隔开即可,如果有多个背景图片,而其他属性只有一个(例如background-repeat只有一个),那么所有背景图片都应用该属性值。

下面我们就看一个例子吧:

body { background-image: url(https://image.flaticon.com/icons/svg/748/748122.svg), url(https://images.unsplash.com/photo-1478719059408-592965723cbc?ixlib=rb-1.2.1&auto=format&fit=crop&w=2212&q=80); background-position: center, top; background-repeat: repeat, no-repeat; background-size: contain, cover;}


推荐教程:《html视频教程》