Home arrow Style Sheets arrow Page 3 - Using Span Tags for Image Replacement
STYLE SHEETS

Using Span Tags for Image Replacement


In this fourth part of a six-part series on image replacement, I explore a CSS-based image replacement method originally created by Todd Fahrner. It bases its functionality on using a couple of extra <span> tags to hide the text wrapped by a targeted web page element, while keeping its background image visible.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 3
November 25, 2009
TABLE OF CONTENTS:
  1. · Using Span Tags for Image Replacement
  2. · Review: Mike Rundle's image replacement method
  3. · Working with non-empty span tags
  4. · Combining the CSS and the structural markup

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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!


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials