The rollover mishap, and how to avoid it.

Having trouble getting your CSS rollovers un-glitchy? Pre-load them, easily… If HUGE can learn from me, so can you! ;) (I’m saying this jokingly.)

Yes, this a real email I sent HUGE. They fixed the problem by doing exactly as I said. And they didn’t even say THANK YOU!

I’ve sent this same sort of email to lots of people - including some pretty great designers and developers. All not preloading their rollovers. So, for the sake of helping to spread the gospel of the css preload, I’m just going to email everyone the link to this article from now on…

Some of you asked for a video (okay, one person). I love clusterflock, and they don’t have non-semantic HTML (despite putting H2s before H1s), but they’ve got the same problem with CSS rollovers: clusterflock rollover (144KB) (Did you catch the glitch?)


From: noel@eight6.com
Subject: Attention, you have a website bug…
Date: February 20, 2008 12:27:29 AM GMT-05:00
To: nameremoved@hugeinc.com
Hi HUGE!

You’ve got a problem with your website. Albeit a small one, but one a pro should not make.

Your hover state on your div element with the #logo id isn’t preloading the hovered image. Thus, you get a flicker on the hover state when the image has not been cached. On a slow connection this can be from a half second to 2 or more seconds. Bad implementation.

First things first, you are using incredibly non-semantic markup for your header. I specialize in standards compliant markup and have been doing so for 10 years.

Your code SHOULD look something like:
<h1 id="logo"><a href="/">HUGE</a></h1>

NOT LIKE THIS: <div id="logo"><a href="/"></a></div> BAD!!! BAD!!!

I know you don’t need better search results, as you get plenty of clients already. But, by being the best, you should really have the best code… you don’t.

Again, to fix the bug, that I’ve also put onto video here:
http://eight6.com/assets/huge_hover_problem.mov

To fix it, preload the hover image by implementing the following CSS, that loads the default image behind the link in a container div.

#logo {
/* This is the line that prevents the flicker when hovering */
background:url(/imgs/logoBlack.gif) no-repeat;
}

#logo a,
#logo a:link,
#logo a:visited {
background:url(/imgs/logo.gif) no-repeat;
display:block;
width:144px;
height:57px;
}

#logo a:hover,
#logo a:active {
background:url(/imgs/logoBlack.gif) no-repeat;
}

BTW, I am in NYC this week for client work if you would like to meet me and I can show you the problem. Or feel free to call me at 734-642-9187

I think you guys do amazing work. Keep it up… and if you need a hand keeping that code tight and more semantic, please let me know.

Best,
Noel Jackson

-
noel jackson
founder eight6 | http://eight6.com
noel@eight6.com
+1.734.642.9187

Sphere: Related Content

6 Responses to “The rollover mishap, and how to avoid it.”

  1. Avatar Dean Says:

    Does your back get sore from hauling your GIANT BALLS around! :)

  2. Avatar noel Says:

    HAHA! Thanks Dean. Ego: in-check. ;)

  3. Avatar zeldman Says:

    Thanks, Noel. My code sucked until you fixed it. You are teh awesome!

  4. Avatar pat Says:

    Actually, I think the method I’ve been using for years…

    http://www.wellstyled.com/css-nopreload-rollovers.html

    …is a better choice, overall.

    I also strongly disagree that is superior to Company or for a logo. should be reserved for the primary subject of the web page. Take this default WP template - is the page primarily about “Leaves Rustle” or is the page about “The rollover mishap, and how to avoid it.”?

    I think the answer is clear where the should be. Semantically speaking, that is. ;)

  5. Avatar pat Says:

    Arg! It stripped my markup!

  6. Avatar noel Says:

    @pat Your method is a lot like CSS sprites (http://www.alistapart.com/articles/sprites)

    I’ve used the CSS sprites method before, but it’s just not time-friendly to put together one image for rollovers sometimes. Nor is it really worth the effort, especially if you can preload easily.

    It depends if you view the H1 as an element for emphasis or for hierarchy. I view it as the latter. I think the title of the blog “owns” the rest of the content, therefore I like it as an H1.

    Thanks for your thoughts… it is something to think about.

Leave a Reply

Related Posts by Category

Related Posts by Tag