Advertise
Drop Me an Entrecard
Top Entrecard Droppers
Categories / Archives
Top Level Web Directory Categories
Subscribe
Add to Google Reader or Homepage Subscribe in NewsGator Online
Add to My AOL Add to netvibes Subscribe in Bloglines

  • Posted the Entrecards, The Dropper How To (http://tinyurl.com/6hmg5o) another great How To from Lobo Links
  • Congrats to Entrecard for their latest creation Entrebar http://tinyurl.com/5pygbw. Now if they could only cure that bounce rate problem.
  • Auto Industry reports truck and suv sales decline according to the WSJ. Gas in MS is 3.45'ish a gallon. http://tinyurl.com/5np6gf
  • Published a new post: Bounce Rate, Part of the Google Quality Metric? ( http://tinyurl.com/6napz8 )
  • Published a new post: Top Entrecard Droppers for July 2008 ( http://tinyurl.com/54pzw6 )

CSS Image Replacement, The How To

October 10th, 2007 by Mack

CSS Image replacement is very affective for style sheet based themes. The advantage of using image replacement is compatibility for screen readers or non-image based browsers that can not use my .css document. If I did not do this, then non-image based browsers would not be able to navigate my site easily and effectively.

This is what it looks like to image enabled browsers

headerexample.jpg


This is what it would look like to non-image based browsers

headerexample21.jpg



The Logo, Method 1

As you can see I did the main logo image and the menu for the header, but I did both with two separate methods. I will discuss the logo first. It is created using two css IDs.

The first ID is a the image wrapper.

CSS:
  1. #logoimage {height:100px;width:341px;background: url(../images/logo.gif) no-repeat;}

Note maybe the most important part of this is the height/width and no repeat tagged on the end.

The second ID belongs to the actual a href linking code.

CSS:
  1. #logolink { display:block; width:341px;height:100px;text-indent: -999px;overflow: hidden;}

Note the height/width are exactly the same as the image and my text-indent is a negative value because the logo is on the left side of the screen.

The Html

HTML:
  1. <div id="logoimage"><a href="http://www.lobolinks.com" id="logolink" title="Lobo Links Web Directory">Lobo Links Web Directory</a></div>

The Menu, Method 2

Next up is the Menu, which uses one css ID and one css class. This method has very similar characteristics to the first and works basically the same way. Just less actual html code is used.

This is the css used for the home button, but the same methods apply to all of your menu buttons.

CSS:
  1. #btn-home{
  2.     display:block;
  3.     float:left;
  4.     background: #001e2d url(../images/btn-home.gif) no-repeat;
  5.     height:100px;
  6.     width:66px;
  7. }

Note maybe the most important part of this is the height/width and no repeat tagged on the end.

CSS:
  1. .btn-home { display:block; width:66px;height:100px;text-indent: 999px;overflow: hidden;}

Note the height/width are exactly the same as the image and my text-indent is a positive value because the menu is on the right side of the screen.

The Html

HTML:
  1. <a href="http://www.lobolinks.com" id="btn-home" class="btn-home" title="Home">Home</a>

Thats It! Let me know what you think.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • StumbleUpon
  • Sphinn
  • Mixx
  • Reddit
  • Technorati

Related Post

8 Responses

  1. By SomeDude on Oct 11, 2007 | Reply

    I've clearly missed something. Why do you advocate this more difficult method instead of using the standard of using an IMG tag? Your advocation using a css background-image here when in fact you're not placing the image in the background of anything. You also violate the "Text is not an image" rule. Aren't nav items more appropriate as UL/LI? Totally confused why this is the "correct" way to do it.

  2. By Mack on Oct 11, 2007 | Reply

    This provides everyone a way to navigate your site if your using navigational images derived from a CSS template.

6 Trackback(s)

  1. Oct 10, 2007: GadgetGadget.info - Gadgets on the web » CSS Image Replacement, The How to’s
  2. Oct 11, 2007: Search Engine Optimization Blog » Rewriting the Beginner’s Guide - Part I continued
  3. Nov 7, 2007: Ruby, Rails, TextMate, JavaScript, CSS, Web Usability, Mac OS X « exceptionz
  4. Nov 8, 2007: PlugIM.com
  5. Nov 9, 2007: » Googles link policing, Gooruze Launch and Opensocial opens its doors- TGIF SEO Links | Brian Chappell
  6. Jun 20, 2008: CSS Image Replacement For Fixed Width Themes : Lobo Links Blog

Leave a Reply