The project I'm working on is a 1 page website that is split up into sections, the first section is the masthead with a background image applied to it. My goal is to make this image responsive on resize, so I set the background-size
property to cover
When scaling the viewport on a desktop browser, the image scales accordingly. However on mobile clients (tested on iOS 7 and Andriod Froyo/Kitkat) the image seems to stay at it's full width/height, becoming very pixelated and distorted.
example: http://www.bardiadoust.ca
At first I thought the problem was with the -500% margin and 500% padding I had on the left/right of each section (I'm using this to create full width sections while keeping the content inside my grid). I took out this code and was still getting the same result. If anyone has any clues as to what I'm doing wrong, that'd be great.
Update
I've been doing more investigating and thought that this might be an iOS issue due to image size limits (Read More Here) and swapped out my rather large 1.2mb image with a 500k gif. The problem however, persists.
Update 2
Haven't found a full solution yet, but I have found a fix I'm happy with.
In my global styles I have these background properties set on .masthead section:
background: $tangerine;
background:
linear-gradient(
rgba(232,85,4, .84),
rgba(232,85,4, .84)
),
url("../images/pano2.png") no-repeat center center;
-webkit-background-attachment: fixed;
-moz-background-attachment: fixed;
-o-background-attachment: fixed;
-ms-backgroudn-attachment: fixed;
background-attachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
On my first media query break point I apply these styles to .masthead:
@media only screen and (max-width: 959px){
-webkit-background-attachment: scroll;
-moz-background-attachment: scroll;
-o-background-attachment: scroll;
-ms-backgroudn-attachment: scroll;
background-attachment: scroll;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
}
contain
seems to give me the result on mobile that I'm looking for, but only if the background-attachment
property is not set to fixed
. This wasn't too big of a trade off for me since fixed backgrounds don't really work properly on mobile devices anyway.