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!

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

My background keeps scrolling on my iPhone Chrome/ Safari

Hi folks, on my site I have a my background attachment fixed. It works fine on desktop, and android phones. But on my iPhone, the background keeps scrolling and since I have repeat to no, it becomes the background color.

You can check it out here

body {

    font-family: 'Lobster', helvetica neue, helvetica, ariel;
    font-weight: normal;
    line-height: 1.3;
    margin: 0 auto;
    padding: 0 5%;
    background-color: #1b212c;
    background-image: url("../img/bgIMG.jpg");
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: #fff;
}

Ok to the best of my knowledge and research it looks like the CSS rule background-attachment is automatically disabled on iOS, but it runs fine on Android though(tested it myself).

One thing that kind of helped was

background-size : cover;

It basically covered my screen where there is a scroll-able page. It's not the ideal solution but it's something folks

¯_(ツ)_/¯

Michal Janecek
Michal Janecek
8,194 Points

There is an issue with using background-attachment: fixed with background-size: cover on IOS devices (http://caniuse.com/#search=background-attachment ... the known issues section). From quick search on the web you can try and use a div covering the whole viewport and set background image to it like this:

<div style="
width:100%;
height:100%;
background-image:url("mybg.jpg");
background-size:cover;
position: fixed;
z-index:-1;">
</div>

Hi Michal thanks and I tried fixing it using that method but no good.

But thanks for the update.

1 Answer

My solution

body {
    background-attachment: fixed; //for web and supported mobile devices
    background-repeat: no-repeat; //
    background-size: cover; // for iphone devices
    color: #fff;
}