In website-design, the CSS text-replacement technique is well-known (see for example the article on the subject at Stopdesign).
What I have not seen elsewhere, though, is a technique to make sure the text is not only replaced, but also shows an underline when the mouse is hovered over it, for a typical hyperlink-effect.
Consider the situation where you want to show a header in a special font (which visitor probably won’t have). and you want this header to be clickable. You want the header text to become underlined when hovered over with the mouse, to clearly indicate this is a hyperlink.
The solution is very simple:
- make sure your replacement images are placed on a background that has a plain color;
- paint the background in your images with the same background color;
- in the image, make all pixels transparent that should show up as the underline;
- in the CSS, set the background of the images to match the background color;
- in the CSS, add a :hover rule that changes the background color for the images to match the text color (instead of the background color).
For a working example, check out this site:
Update (July 23, 2007): Note that in order for this hack to work with PNG images under MSIE 6, you will need to save the backgroud color in the image and use an indexed PNG.