I am using the text-indent
technique to replace my <h1/>
tag with my website's image as so:
<h1 title="Homepage">My logo</h1>
CSS:
#header h1 {
float: left;
background: transparent url('../images/logo.png');
width: 214px;
height: 64px;
text-indent: -9999px;
}
The only problem is that I want to still have the new image act as a hyperlink. I tried doing:
<h1 title="Homepage"><a href="#">My logo</a></h1>
But since it is being indented, the link is too. I wanted to know if anyone had any suggestions on how to do this and still be valid XHTML.
EDIT I'd rather do it in a way that is accessible to users with screen readers, from what I read, doing a display:none
will not work with some readers.
@Partrik Hägne: You should't use
display:none
, because some screen readers will ignore that...You can see a list of Nine Techniques for CSS Image Replacement on http://css-tricks.com, which describes the cons and pros for each solution.
Why are you mucking about with negative indents - just use the alt attribute of the img tag?
There are many ways to do this, this is the way that I prefer, it works well, and is easy to implement.
Then i do this css, this is also know as the "Leafy/Langridge image replacement" method
The only thing you should have to edit is the
height
, and thepadding-top
. In this example it is22px
, this should be equal to your image-height.What you can do is remove the indent. And use a span to hide instead:
You might have to set the width and height of the A-tag also since nothing fills using this trick.