background-image属性怎么用

2020-07-23 09:51:39
background-image属性是用来设置元素的一个或多个背景图像,用逗号(,)分隔。

CSS background-image属性

作用:background-image属性为元素设置背景图像。

语法:

background-image:url(图片路径)

说明:background-image属性设置的背景图像会占据了元素的全部尺寸,包括内边距和边框,但不包括外边距。默认地,背景图像位于元素的左上角,并在水平和垂直方向上重复。

提示:请设置一种可用的背景颜色,这样的话,假如背景图像不可用,可以使用背景色带代替。

CSS background-image属性的使用示例

<!DOCTYPE html><html><head><meta charset="utf-8"> <style>#example1 {    background-color:#cccccc;    background-image:url("https://img.php.cn/upload/article/000/000/024/5c6a290265dba776.gif"),url("https://img.php.cn/upload/article/000/000/024/5c6a2793a13ac244.gif");    background-position: right bottom, left top;    background-repeat: no-repeat, repeat;    padding: 15px;}</style></head><body><div id="example1"><h1>Hello World!</h1><p>测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!</p><p>测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!测试文本!</p></div></body></html>

效果图:

1.jpg