简体   繁体   中英

How to set background image with full width and responsive

Im trying to set a background image and set this to be full witdh but im only getting to see it centered.

 .wrapper-hero { width: 100%; height: auto; max-width: 1920px; } .wrapper-hero .hero-image { background: url('@{baseDir}images/hero-image.png') no-repeat top center; background-size: contain; background-repeat: no-repeat; display: block; background-size: cover; height: 800px; width: 1200px; } 
 <div class="wrapper-hero"> <div class="hero-image"></div> </div> 

Any ideas? And the image is not responsive at all...

You're using background-size multiple times. Try this code.

 .hero-image { background: url('@{baseDir}images/hero-image.png') no-repeat center center fixed; width: 100%; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } 

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