在CSS中,背景图像可以通过background-image属性指定。该属性接受一个URL作为参数,用于指定要用作背景图像的图像文件的地址。
background-image: url("image.jpg");
如果要指定多个背景图像,可以使用background属性。该属性可以接受多个参数,用逗号隔开,每个参数对应一个背景图像,可以进一步通过background-position、background-repeat等属性来控制每个背景图片的显示效果。
background: url("image1.jpg"), url("image2.jpg"); background-position: center center, left top; background-repeat: no-repeat, repeat;
如果希望背景图像跟随页面滚动,可以使用background-attachment属性。
background-attachment: fixed;
此外还可以通过background-size属性来控制背景图像的尺寸。该属性可以接受多个参数,也可以使用百分比或具体数值来指定图像的尺寸。
background-size: cover; background-size: 50% 50%; background-size: 100px 200px;
通过这些属性的组合,可以实现各种各样的背景图像效果。