background-attachment messes up rendering in Jelly Bean WebView?

旧街凉风 提交于 2019-12-12 16:09:32

问题


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

回答1:


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;
}



回答2:


for position related and absolute you can use z-index. Read more about z-index: http://www.w3schools.com/cssref/pr_pos_z-index.asp




回答3:


On my website, to make the background image to reappear behind the content (on Jelly Bean browser), I only had to remove the css property: background-attachment: fixed.

Zoltan's solution not worked well to me because it makes the background image does not display correctly in some browsers (tested on browserstack)



来源:https://stackoverflow.com/questions/12391179/background-attachment-messes-up-rendering-in-jelly-bean-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!