做项目中遇到一个小问题 (要让容器与浏览器宽度,高度相等)

    做项目中遇到一个小问题 

要让容器与浏览器宽度,高度相等,可以通过设置html, body的width, height都为100%,然后用body来设置背景图片。也可以通过js自动调整容器的width与height。还有就是我最爱的下面神单位vw, vh。

background-position: center center;
background-size: cover;
background-repeat: no-repeat;
width: 100vw;  // 这个设置容器宽度为浏览器宽度
height: 100vh; // 这个设置容器高度为浏览器高度
background-size:100%;background-repeat:no-repeat;

猜你喜欢

转载自blog.csdn.net/qq_35458793/article/details/71703288