css3 background-size:cover leaving white space on resize

后端 未结 4 1081
抹茶落季
抹茶落季 2021-01-07 01:12
body {
    margin:0;
    padding:0;
    position:relative;
    background:url(../images/imgs/backgrnd.png) no-repeat;
    background-size:cover;
}

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-07 02:10

    It's 2021 and I encountered a similar problem and none of the solutions worked for me.

    I managed to figure it out and hope this will help someone.

    You will need to set the viewport height and width to 100%. According to w3schools, The viewport is the user's visible area of a web page. This will eliminate any white spaces by setting the minimum height to that.

    height: 100vh;
    width: 100vw;
    

提交回复
热议问题