CSSKarma

display your <style>

designing the web since 2002

Quick Tip #1 – Image Replacement

article banner

Problem

Image replacement can be easily abused; but when used properly (like replacing logo text) it’s a great resource.

Image replacement without extra markup usually means setting text-indent:-9999px on your link. And this works great great. But in a lot of browsers it leaves a focus outline that runs way off the page to the left on click.

welovebeans.com logo with a :focus outline the runs off the page

We need to keep the outline there for accessibility reasons, so most developers just leave it alone. But there’s a way to make, both, designers and accessibility gurus happy.

view demo

Problem CSS

#branding h1 a{
display:block;
height:70px;
width:289px;
background:url(../images/logo.png) no-repeat 0 0;
text-indent:-9999px;
}

Goal

welovebeans.com logo with proper :focus outline

Solution

By adding overflow:hidden to the link we can cut off the extended :focus outline.

Solution CSS

#branding h1 a{
display:block;
height:70px;
width:289px;
background:url(../images/logo.png) no-repeat 0 0;
text-indent:-9999px;
overflow:hidden;
}

view demo

Tags:

You can leave a response, or trackback from your own site.

|

Comments (6)

  1. Christian says:

    Thanks for the tip! That’s an annoying probem

  2. Alex says:

    I usually remove the outline all together, but I didn’t realize the accessibility reasons for keeping it. thanks for the tip

  3. Ryan says:

    The web design company I work for puts their text in a tag inside the <a> and sets the to display:none.

    That way you don’t have to ever worry about it showing. But either way works and I wonder what the pros and cons of each are..

  4. Olaf says:

    i can’t see any difference between the two oulines viewing the demo with internet explorer. with firefox there’s the difference. but for all that – thanx for the tip

  5. Dennison Uy says:

    I have always been annoyed by this. I didn’t know that the solution was this simple. Good tip!

|

Leave a Reply

New from the blog

Are My Sites Up? authenticjobs.com