Search code examples
androidcssandroid-webviewandroid-4.2-jelly-bean

background-attachment messes up rendering in Jelly Bean WebView?


It seems that the background-fixed CSS property doesn't work right in Jelly Bean WebView (both inside an application and using the default Android browser).

If I set this property, the background image gets loaded over the content, i.e. the content is behind the background image.

Here's my relevant HTML code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">   
<meta name="viewport" content="target-densitydpi=device-dpi">
<meta name="viewport" content="initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="./gesture-background_files/genre-channel-background.css">
<style type="text/css"></style></head>
<body>
<div id="right-keys">
    <a href="keypress://1"><img src="./gesture-background_files/one.png"></a><br />
    Film24<br />                    
</div>
<div id="right-keys-vertical">
    <a href="keypress://1"><img src="./gesture-background_files/one.png"></a><br />
    Film24<br />
</div>
<div id="footer">
    MUSCADE<span class="large">EPG</span>
</div>   
</body>
</html>

And here's the relevant part of the CSS:

body {
    background-image: url(hot-black-background.jpg);
    background-color: black;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: bottom left;
}

#right-keys, #right-keys-vertical {
    position: absolute;
    right: 10px;
    width: 100px;

    text-align: center;
    text-shadow: black 2px 2px 0px;
}

#right-keys img, #right-keys-vertical img {
    height: 90px;
    margin-bottom: 0;
}

#footer {
    position: absolute;
    right: 10px;
    bottom: 10px;
    font-size: 20px;
}

It's a bit long, but the only important part are the background-attachment and background-position properties on top of the CSS file. If I remove those, everything works fine.

Is this a known bug? Can anyone suggest a workaround?

Here's a link to the file so you can try opening it from a Jelly Bean native browser (not Chrome):

http://212.92.197.78/gesture/gesture-background.htm

Solution

  • It turns out that in the Jelly Bean browser if you use

    body {
       background-image: url(any-image.jpg);
       background-attachment: fixed;
       background-position: bottom;
    }
    

    or anything involving bottom or right for background-position, any elements you position with reference to the right or bottom edge of the screen will be overlaid by the background image.

    This is most certainly a bug in Jelly Bean's browser.

    Instead of using the above, I put a background image on my page using the following code:

    HTML:

    <body>
       <img id="background" src="any-image.jpg" />
       (...)
    </body>
    

    CSS:

    #background {
       z-index: -1;
       position: fixed;
       bottom: 0;
       left: 0;
    }