Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS position:fixed causes blurry images in Android Browsers

No one ever quite answered this similar question,

Blurry images on stock android browser

So I'm going to post my own version specific to my situation.

The problem is that position:fixed causes child image elements to be blurry in some android browsers. In my case, it causes the stock browser of Galaxy Note v1 running Android 4.0 to experience this issue. Others have said the same thing for some Galaxy S3. Here's my code:

Preview @ http://jl.evermight.net/blurryposition/

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, maximum-scale=1.0,initial-scale=1.0, user-scalable=no" />
    </head>
    <body>
        <div id="top-nav-container"
        style="
        display:block;
        top:0px; 
        position:fixed;
        width:100%; height:5.2rem;
        ">
            <a style="background-image:url(logotest_big.jpg);
            background-size:20%;
            display:block;
            width:500px;
            height:200px;
            "></a>
        </div>


    </body>
</html>

You'll notice that the OPTIX Testing logo is blurry at first. If you remove position:fixed from the #top-nav-container, then the logo is crisp and clear. So my question is, how do I keep both position:fixed and a crisp logo?

In my real website, the top navigation is supposed to stay fixed while you scroll through the site. I tried using position:absolute and using javascript to reposition the top navigation on scroll, but that caused a whole bunch of jumping/flickering effects. So if I can't use position:fixed or position:absolute to fix the top navigation to the top of a mobile web browser, what are my other options? How do other mobile websites achieve this result?

Additional Info:

I did some more experiments with the resizing image, changing view port, and changing the position:fixed/absolute and came to some interesting results. See below:

  • position:fixed no-background-size with-viewport - fuzzy
  • position:fixed no-background-size without-viewport - crisp
  • position:fixed background-size:20% with-viewport - fuzzy
  • position:fixed background-size:20% without-viewport - fuzzy

  • position:absolute no-background-size with-viewport - fuzzy

  • position:absolute no-background-size without-viewport - crisp
  • position:absolute background-size:20% with-viewport - crisp
  • position:absolute background-size:20% without-viewport - crisp

Here's how to read this chart:

  • first column states whether #top-nav-container is using position:fixed or position:absolute

  • second column states if i used background-size:20% or if i omitted it

  • third column states whether i included the <meta viewport> tag in the head

  • fourth column states whether the optix testing logo is fuzzy or crisp.

Looking at the results, you can see that the only time you get a crisp image with a container that has position:fixed is when an image has not been stretched or compressed via background-size or or with the view port. Also, the only time you get a fuzzy image with a container that has position:absolute is when an image has been stretched with background-size and with a viewport.

like image 245
John Avatar asked Jun 27 '13 13:06

John


2 Answers

Using position: fixed is still a bad idea on mobile devices. The overwhelming majority of websites fall back to a static header for mobile views (ie. no floating navbar).

I experienced similar issues recently, as illustrated in this question.

A few resources for you:

  • Read this article on Quirksmode to learn about the problem: http://www.quirksmode.org/blog/archives/2010/12/the_fifth_posit.html
  • See which mobile browsers support position: fixed in this table: http://caniuse.com/#search=fixed
like image 115
Graham Swan Avatar answered Nov 18 '22 08:11

Graham Swan


add &nbsp; inside top-nav-container.

<div id="top-nav-container"
    style="
    display:block;
    top:0px; 
    position:fixed;
    width:100%; height:5.2rem;
    ">
        <a style="background-image:url(logotest_big.jpg);
        background-size:20%;
        display:block;
        width:500px;
        height:200px;
        "></a>
        &nbsp;
    </div>

I got this problem too when creating fixed action bar with div using background-image as icon. But when I add Text in that action bar, that background-image become crisp. So I just add &nbsp; as replacement for Text if I don't want any Text on my action bar.

Sorry for my bad English :D

like image 1
Sudhanta Suryaputra Avatar answered Nov 18 '22 09:11

Sudhanta Suryaputra