简体   繁体   中英

How to make a fully responsive background image that works even in iPhone Safari?

I tried different methods, mostly people suggest to use img instead of a background-image to get the perfect result, but I was wondering is it possible to fix this with just some tricks and have a full-width background image?

Here's my live website that I have problem with

Since you do not need the img to fill the page vertically and I think that you want the whole image to fit horizontally this is how I would do it.

body { 
  background: url(http://lorempixel.com/400/200/sports/) no-repeat center center fixed; 
  -webkit-background-size: 100%;
  -moz-background-size: 100%;
  -o-background-size: 100%;
  background-size: 100%;
}

see fiddle http://jsfiddle.net/DIRTY_SMITH/x131ofex/3/

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