htmlcssbackground-imagebackground-repeat

why image not stretching verticlly


I have written the following code and I simply cannot understand why the image I have setted to be on the background doesn't strech vertically to cover the full page . I would appreciate your help

html{
    height: 100%;
    overflow-y: scroll;
}
html:after{
    margin-bottom:0;
    content : "";
    background: url("../images/van1.jpg") no-repeat center center;
    background-size:cover;
    width: 100vw;
    height: 100vh;
    position: absolute;
    overflow: hidden;
    top: 0;
    left: 0;
    opacity: 0.5;
    filter: alpha(opacity=50);
    z-index: -1;
}`

Solution

  • Using html:after is like adding a child inside <html> beside your <body> tag, it's not valid and browsers may not render it correctly, it's better using body:after and set height: 100% so it covers your page.