Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

background-size: cover not working on iOS

This is my code:

background-color:#fff; background-attachment:fixed; background-repeat:no-repeat; background-size:cover; -moz-background-size: cover; -webkit-background-size: cover; -o-background-size: cover; background-position: center center;  

It's working on desktop, iPad and Android mobile:

working

On Chrome and Safari on iPhone, the background is too big:

too big

like image 981
Hoàn Nguyễn Avatar asked Jun 11 '14 04:06

Hoàn Nguyễn


People also ask

Why does my background image not cover the whole page?

Try setting your header to height: 100% . Alternatively (the better solution), set the background on the body if you want it to cover the whole page.

How does background-size cover works?

If the background-size is contain or cover : While preserving its intrinsic proportions, the image is rendered at the largest size contained within, or covering, the background positioning area. If the image has no intrinsic proportions, then it's rendered at the size of the background positioning area.


1 Answers

This happens, particularly on iOS, when you have background-attachment:fixed. On mobile, I usually put background-attachment:scroll inside of a @media query.

As @RyanKimber pointed out, fixed attached images use the whole <body> size. On mobile this can get really tall which blows your image out. Setting the attachment back to scroll allows your cover image to stretch within its own container.

like image 106
Matt Fiocca Avatar answered Oct 10 '22 06:10

Matt Fiocca