简体   繁体   中英

100vh not making image 100% of viewport

I am attempting to use 100vh to make a background-image always have a height per the size of the screen. What I am wanting to do is use the same image for each viewport and allow the overflow: hidden to make due of the access width. In essence, narrowing the image more vertically. However, my attempt is not working. The background-image is not adjusting to the 100vh.

Does anyone see what I am doing wrong?

 #home-cover1 { background-image: url("/images/home-cover1.jpg"); background-repeat: no-repeat; background-size: 100%; height: 100vh; width: 100%; position: relative; } #home-cover1-wrap { background-color: rgba(0,0,0,0.3); top: 0; left: 0; right: 0; width: 100%; height: 100%; } 
 <div id="home-cover1"> <div id="home-cover1-wrap"> </div> </div> 

Change CSS I think background-size: cover; is Best

#home-cover1 {
    background-image: url("https://optimumwebdesigns.com/images/home-cover1.jpg");
    background-repeat: no-repeat;
    background-size: cover;
    height: 100vh;
    width: 100%;
    position: relative;
}

Your #home-cover1 background-size lack the 100% of height, change background-size: 100%; to background-size: 100% 100%;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM