Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Background Cover Images Not Displaying Correct On Mobile Device

Hi everybody,

I'm not sure if something like this has already been asked on here but I've been working on a clients website and things appear fine on the desktop version of the website and also look fine when the browser is sized down.

When I load the website on my iPhone (6), the Background Cover images don't seem to resize or be responsive, they just remain very large and zoomed in so that you're not able to make out what the image is.

I'm wondering if anybody has any tips on solution here, I've been searching around on how to resolve this but not had much luck so far.

Thanks in advance.

Check to make sure you have added a meta tag to override the device viewport so it doesn't auto-zoom.

  <head>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/styles.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>

More on meta : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta

You might need to check your width/max-width settings for the images, too. I had an issue with Safari and Firefox not resizing some images so had to add both a max-width and width setting for images (though this wasn't a background image).

img {
  max-width: 100%;
  width: 100%; /* Add width to fix Firefox/Safari image scaling issue */
}

1 Answer

Can I use says there are some bugs in iOS Safari for background-size: cover:

  • "iOS Safari has buggy behavior with background-size: cover; + background-attachment: fixed;"
  • "iOS Safari has buggy behavior with background-size: cover; on a page's body."