css3 background-size:cover leaving white space on resize

后端 未结 4 1125
抹茶落季
抹茶落季 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 01:56

    Not sure if you solved this problem, but I was tearing my hair out over it for a couple of days and nothing I could Google was helping. I talked to someone at work on our UI team and it turns out that the body of the web page won't necessarily cover the whole height of the page. Adding the following to my css file completely solved the problem:

    html {
        height: 100%;
    }
    
    body {
        background-size: cover;
        height: 100%;
    }
    

    This stretches the content of the body to fit the whole height of the window. Just including the "body" bit worked for me, but my coworker informed me that it's better to include both because some browsers will act funny with just one.

提交回复
热议问题