CSS 允许使用纯色作为背景,也允许使用图片作为背景
background-color 属性用于设置背景颜色
background-image 属性用于设置背景图片
background-repeat 属性用于设置对背景图片进行平铺
background-position 属性用于设置背景图片的对齐方式
background-attachment 属性用于固定背景图片,如果文档比较长,那么当文档向下滚动时,背景图像也会随之滚动
p {background-color: gray;} ????????????# 为段落设置背景颜色 ????????????
body { ????????????????????????????????????????background-image: url(dora.jpg); ???# 为文档主体设置背景图片,需要指明图片路径 ???background-repeat: no-repeat; ??????# 设置背景图片不平铺,默认会水平和垂直平铺,no-repeat(不平铺); repeat-x(水平平铺); repeat-y(垂直平铺)
???background-position: center; ???????# 设置背景图片居中显示,常用的值有:top、bottom、left、right、center
???background-attachment: fixed; ??????# 固定背景图片,默认值是scroll,也就是说,在默认的情况下,背景会随文档滚动}
CSS 背景
原文地址:https://www.cnblogs.com/pzk7788/p/8282317.html