Home arrow Style Sheets arrow Page 3 - Using Empty Span Tags with H2 Headers for Image Replacement
STYLE SHEETS

Using Empty Span Tags with H2 Headers for Image Replacement


In this eighth installment of a series on image replacement techniques, you'll learn how to use Fahrner’s enhanced image replacement method for styling all of the H2 elements included in a sample web document. This method uses two empty <span> tags in a clever way which permits you to efficiently solve the problem caused by broken background images.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
December 08, 2009
TABLE OF CONTENTS:
  1. · Using Empty Span Tags with H2 Headers for Image Replacement
  2. · Review: the enhanced Fahrner's IR technique
  3. · Styling H2 elements with Fahrner's enhanced IR method
  4. · Putting it all together on one web page

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using Empty Span Tags with H2 Headers for Image Replacement - Styling H2 elements with Fahrner's enhanced IR method
(Page 3 of 4 )

If you found it really easy to use Fahrner’s enhanced IR approach with a single H1 element of a web document, then you’ll quickly grasp how to perform the same task with the document’s H2 headers. Since the best way to understand the inner workings of this styling process is by example, in the lines to come I coded the set of CSS styles required for replacing the text wrapped by the headers in question with a basic background image.

Having explained that, here are the aforementioned CSS styles:

 

h2 {

position: relative;

width: 300px;

height: 150px;

margin: 0;

padding: 0;

overflow: hidden;

}

h2 span {

display: block;

position: absolute;

left: 0;

top: 0;

z-index: 1;

width: 300px;

height: 150px;

margin: 0;

padding: 0;

background: url(h2.gif) top left no-repeat;

}

From this code sample, it’s clear to see how this IR method works. All of the H2 selectors have been relatively positioned in the XHTML document, while the corresponding child <span> elements have been located absolutely, a process that overlaps the assigned background image with the headers’ inner text.

In addition, to complement the previous explanation, below I've placed the background image used in this concrete example:

Obviously, to achieve the desired visual effect, this image shouldn’t contain any transparent sectors, so keep this important detail in mind before you start creating your own replacement background graphics!

So far, so good. At this point, you’ve surely grasped how to use Fahrner’s enhanced IR method to give a more appealing look to all of the H2 headers of a web document. So, what’s the next step? Well, logically the earlier CSS styles must be tied to the structural markup, to make it possible to see the actual functionality of this image replacement approach.

This will be done in the following section, so read the lines to come.


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 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials