tags:

views:

3664

answers:

6

I have a tag in my html like this:

<h1>My Website Title Here</h1>

Using css I want to replace the text with my actual logo. I've got the logo there no problem via resizing the tag and putting a background image in via css. However, I can't figure out how to get rid of the text. I've seen it done before basically by pushing the text off the screen. The problem is I can't remember where I saw it.

Thanks.

A: 

The answer is to create a span with the property

{display:none;}

You can find an example at this site

Andrei Krotkov
+3  A: 

the most cross-browser friendly way is to write the html as

<h1><span>Website Title</span></h1>

then use CSS to hide the span and replace the image

h1 {background:url(/nicetitle.png);}
h1 span {display:none;}

if you can use CSS 2, then there are some better ways using the content property. but unfortunatly the web isn't 100% there yet.

ozone
But be sure to also set the width and height attribute to that of the image - and make sure "padding" and "margin" are set because browsers have different ideas as to how much padding/margin a H1 tag needs to have.
nlaq
The drawback here is if images are turned off, or if a css-aware bot shows up, the title won't be visible.
willoller
The important text within display none will probably be missed by search engine bots and screen readers. Use text-indent instead.
dylanfm
A: 

you can use the css 'background-image' property and 'z-index' to ensure the image stays in front of the text.

Jobo
+9  A: 

This is the proper way.

h1 {
    text-indent: -3000px;                 //sends the text off-screen
    background-image: url(/the_img.png);  //shows image
    height: 100px;                        //be sure to set height & width
    width:  600px;
    white-space: nowrap;                  //because only the first line is indented
}

h1 a {
    outline: none;  // prevents dotted line when link is active
}
nicholaides
long titles will have an issue with this method since only the text before word-wrap is indented, and the W3C spec doesn't specify a situation for negative indent so this could have unpredictable results
ozone
If you use this method, you should add "overflow: hidden" to prevent seird selection box shooting off to the left (especially with links)
willoller
If you have any links in elements with the negative text-indent, make sure you also specify "outline: none" otherwise you get a dotted border going off the left of screen.
nickf
This is the correct way.
dylanfm
I prefer to use 'text-indent: -9999px;' just to make sure the text goes really far off the screen. A bit of defensive paranoia.
Andy Ford
Also add 'white-space: nowrap' just to be on the safe side if your text is long as only the first line is indented.
Andrew Moore
+1  A: 

This is actually an area ripe for discussion, with many subtle techniques available. It is important that you select/develop a technique that meets your needs including: screen readers, images/css/scripting on/off combinations, seo, etc.

Here are some good resources to get started down the road of standardista image replacement techniques:

http://faq.css-standards.org/Image_Replacement

http://www.alistapart.com/articles/fir

http://veerle.duoh.com/blog/links/#l-10

willoller
+2  A: 

See mezzoblue for a nice summary of each technique, with strengths and weaknesses, plus example html and css.

darasd