Home arrow Style Sheets arrow Page 3 - Image Replacement CSS Techniques
STYLE SHEETS

Image Replacement CSS Techniques


Image replacement is a useful approach for solving certain web design problems. In this first article of a series that examines this technique, we take a closer look at an image replacement approach that relies on assigning a large negative value to the “text-indent” CSS property to hide the text wrapped by a web page element, thus unmasking its background image.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
November 20, 2009
TABLE OF CONTENTS:
  1. · Image Replacement CSS Techniques
  2. · Basic web page for image replacement
  3. · Using image replacement to style an H1 element
  4. · The image replacement method in action

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Image Replacement CSS Techniques - Using image replacement to style an H1 element
(Page 3 of 4 )

One of the most commonly-used image replacement techniques in modern web design is the one developed by Mike Rundle. It relies on assigning a huge negative value to the “text-indent” CSS property, which shifts the text wrapped by a web page element brutally to the left, therefore hiding it. If, aside from hiding its text from view, the element is assigned a background image, the pertinent image will be displayed on screen without any trace of the annoying text. Got the point? Great.

To demonstrate how to apply this IR method to the H1 header of the web page built in the preceding segment, I’m going to use the following background image:

The graphic above may not be the finest artwork, but it's illustrative enough to put Mike Rundle’s approach into action. So, having created the background image, the CSS code required to replace the text of an H1 element on the previous web document will be as simple as this:

/* apply image replacement on H1 element */

#header h1 {

width: 400px;

height: 200px;

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

text-indent: -9999px;

}

As seen in the above code fragment, the dimensions of the targeted H1 element now match the width and height of its background image, apart from assigning a value of -9999px to its “text-indent” property. In doing so, the text of the header will be hidden from display, while the background image will remain visible. Easy to code and read, isn’t it?

Now that you understand how the previous image replacement method does its thing, it’s time to show the modified version of the earlier web page, this time including the above CSS snippet. This will be done in the following section, so go head and 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 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials