background: url("images/animal1.png") no-repeat left top,url("images/animal2.png") no-repeat right top,url("images/animal3.png") no-repeat left bottom;
注意点:
先添加的背景图片会盖住后添加的背景图片
1
background: url("images/animal1.png") no-repeat left top,url("images/animal2.png") no-repeat right top,url("images/animal3.png") no-repeat left bottom,url("images/animal4.png") no-repeat right bottom,url("images/animal5.png") no-repeat center center;
建议在编写多重背景时拆开编写
1
background-image: url("images/animal1.png"),url("images/animal2.png"),url("images/animal3.png"); background-repeat: no-repeat, no-repeat, no-repeat; background-position: left top, right top, left bottom;
完整代码如下:
1
<html lang="en"> <head> <meta charset="UTF-8"> <title>115-多重背景图片</title> <style> *{ margin: 0; padding: 0; } p{ width: 500px; height: 500px; border: 1px solid #000; margin: 0 auto; /* 多张背景图片之间用逗号隔开即可 注意点: 先添加的背景图片会盖住后添加的背景图片 建议在编写多重背景时拆开编写 *//*background: url("images/animal1.png") no-repeat left top,url("images/animal2.png") no-repeat right top,url("images/animal3.png") no-repeat left bottom,url("images/animal4.png") no-repeat right bottom,url("images/animal5.png") no-repeat center center;*/background-image: url("images/animal1.png"),url("images/animal2.png"),url("images/animal3.png"); background-repeat: no-repeat, no-repeat, no-repeat; background-position: left top, right top, left bottom; } </style> </head> <body> <p></p> </body> </html>