#bg{
margin:0px
background: url(images/beijing.png) no-repeat
background-size:100% 100%
background-attachment:fixed
}
扩展资料:
url(images/beijing.png)——图片路径的位置;
no-repeat—— 图片不重复;
center 0px——center是距离页面左边的定位,0px是距离页面上面的定位;
background-position: center 0——就是图片的定位,同上;
background-size: cover——把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。背景图像的某些部分也许无法显示在背景定位区域中;
min-height: 100vh——视窗的高度,“视区”所指为浏览器内部的可视区域大小,即window.innerWidth/ window.innerHeight大小。
css使div背景图片填充的具体操作步骤如下:
1、我们首先打开前端开发工具,新建一个html代码页面。
2、在html代码页面上创建一个用于设置背景颜色的div标签,然后给这个标签添加上class = "bg-img"。
3、设置背景图片,创建style标签,然后在标签里面对类为bg-img设置背景图片、图片不重复、宽、高的样式。
4、保存html代码,使用浏览器打开,这个时候会发现浏览器上的背景图片显示在左上角。
5、回到html代码页面,在bg-img类里添加background-position: center的属性。
6、保存html代码后重新刷新浏览器,这个时候会发现浏览器上的背景图片已经自动居中了。
background: url(../images/login/theme4.jpg) center center no-repeat
background-attachment: fixed
background-size: cover
background-size: 100% background-size的属性可以调整试试cover,100%等