Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Responsive background being squished in portrait mobile

Responsive background being squished in portrait mobile

Problem

I'm having a problem using responsive backgrounds. http://poppykeith.co.uk/index.html looks correct on computer browsers and in landscape on a Mobile browser, however when viewed on a mobile (im using iOS) in Portrait, the image is squished to fit the screen.

How would I go about making the image just zoom in in portrait mode and not stretch?

Thanks

Problem courtesy of: jshjohnson

Solution

The code you wrote almost works, but the min-width:1024px and the width:100% rules are conflicting with each other and causing the squishing effect you see. Basically, width trumps min-width.

The real technique you want to use is to set that image as a background on the body element, and then use background-size:cover to make the browser load it appropriately

body { 
    background: url(images/bg.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

Details: http://css-tricks.com/perfect-full-page-background-image/

Solution courtesy of: Scott Vandehey

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Responsive background being squished in portrait mobile

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×