网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容 知识问答

css设置背景图片居中;css背景图片自动居中

时间:2024-10-13 08:51:37

1、打开前端开发工具,新建一个html代码页面

css设置背景图片居中;css背景图片自动居中

3、设置背景图片。创建style标签,然后在标签里面对类为bg-img设置背景图片、图片不重复、宽、高的样式。样式代码:.bg-img{ height: 100vh; width: 100%; background-image: url(img/car.jpg); background-repeat: no-repeat; }

css设置背景图片居中;css背景图片自动居中

5、回到html代码页面,在bg-img类里添加background-position: center的属性。

css设置背景图片居中;css背景图片自动居中
© 2025 智德知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com