Style Sheets
  Home arrow Style Sheets arrow Page 3 - Using Span Tags for Image Replacement
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Using Span Tags for Image Replacement
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2009-11-25

    Table of Contents:
  • Using Span Tags for Image Replacement
  • Review: Mike Rundle's image replacement method
  • Working with non-empty span tags
  • Combining the CSS and the structural markup

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Span Tags for Image Replacement - Working with non-empty span tags


    (Page 3 of 4 )

    Certainly, one of the most popular image replacement methods that have been used in the last few years by web designers is the one conceived by Todd Fahrner. It makes use of a pair of extra <span> tags to hide the text wrapped by a web page element, thus cleanly displaying its background graphic.

    To get a more intimate knowledge of how this method works, pay attention to the following CSS block. It shows how to apply the method to an H1 element by using the same "h1.png" background image shown in the preceding section:

    h1 {

    width: 400px;

    height: 200px;

    margin: 0;

    padding: 0;

    background: url(h1.png) top left no-repeat;

    }

    h1 span {

    display: none;

    }

    In this case, the H1 header has been assigned the exact dimensions of its background image, a technique shared by Rundle's approach. However, this method uses an additional <span> selector to hide the text of the header from display via a "display: none" declaration, which implies that the markup of the web page must be properly modified so the style assigned to the pertinent <span> element can produce the desired effect.

    By analyzing this initial CSS code fragment, it's easy to deduce two important things regarding the implementation of Fahrner's approach. First, it needs additional markup to do its thing properly, and last but not least, it possesses the same vulnerability as Rundle's method -- if the background image is not downloaded for any reason, the target element becomes inaccessible to users.

    Nevertheless, I suggest for the moment that you keep your attention focused only on the driving logic of this approach. In the next section I'll be including the previous CSS snippet in a sample web document, so you'll be able to see how all of the pieces fit in together.

    Now, jump forward and read the next few lines. We're almost finished here!

    More Style Sheets Articles
    More By Alejandro Gervasio


       · This fourth part of the series explores the image replacement method created by Todd...
     

    STYLE SHEETS ARTICLES

    - Building Rounded Corners with CSS3`s -webkit...
    - Using the Custom -moz-border-radius Property...
    - Using CSS3`s Border-Radius Property to Build...
    - Adding Semantic Meaning to Styled Code Block...
    - Styling Code blocks with CSS: Using pre HTML...
    - Building Rounded Corners with CSS3
    - Finishing a Casual Navigation Bar with CSS S...
    - Defining a Navigation Bar`s Hover State with...
    - Styling a Blog`s Links Bar with CSS Sprites
    - Creating an Artistic Blog Header with CSS Sp...
    - Defining the Active State of Menu Sections f...
    - Styling the Hover State of a CSS Sprite-Base...
    - Building CSS Sprite-Based Navigation Bars
    - Creating Framed Pictures with CSS
    - Using a CSS Shading Effect to Decorate Images







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek