tags:

views:

122

answers:

6

I have a number of links

<a href="/somepage.html" class="link"></a>

and class has background image wich changes on :hover attribute.

Now the problem is how can I put any text inside <a></a> tags for google to catch but also that it doesn't appear cause if it will show it will mess up my background image.

EDIT:

How about this:

 <a href="/somepage.html" class="link"><span style="display: none;">some text</span></a>

Is this SEO friendly? Will google catch anchor?

A: 
 .link {display:none;}
antpaw
This will hide the entire element, including the background image.
David Dorward
A: 

If I understand the question correctly, you want only a part of the content inside the A element to be visible. In that case…

HTML:

<a href="foo.ext">Some text that will be visible <span>(some text that won’t be visible)</span></a>

CSS:

a span {
 display: none;
}

If you want to have content inside the A element (link text) and use CSS to replace those contents by an image, you could do this:

HTML:

<a href="foo.ext">Descriptive link text goes here</a>

CSS:

a {
 display: block; /* or inline-block */
 text-indent: -9999em;
 overflow: hidden;
 background: url(image.png) no-repeat 0 0;
 width: 500px; // set this to match the width of the background image
 height: 500px; // set this to match the height of the background image
}

 a:hover {
  background-image: url(hover-image.png);
 }

Note that it would be better to use a sprite image containing both images.

Mathias Bynens
This hides the content from screen readers.
David Dorward
Yeah, but that’s what OP asked for, isn’t it?
Mathias Bynens
There are ways to do it without causing the problem (and without having to add extra markup for that matter). It isn't generally a good idea to implement techniques that open you up to litigation (e.g. under the UK's DDA).
David Dorward
Nope, my a href tag has backround image which changes on hover and needs to display always and text in <a> tag must not display.
dfilkovi
David Dorward's solution doesn't cause the problem with screen readers.
adamse
I was just editing my post while you guys where commenting. Please see the edit.
Mathias Bynens
+1  A: 

I recommend against the entire approach of using background images as substitute content, but if you really insist on doing it, then this approach causes the fewest issues:

{
    text-indent: -5000em;
}
David Dorward
Incomplete answer — you need to add `display: block`, because `a` is an inline element by default. Also, you didn’t explain how to add the background image.
Mathias Bynens
The question makes it clean that it **already** has a background image (which means it already is `display: block` or `display: inline-block` or `float: left` or something that makes it a block, otherwise the image would already be invisible.
David Dorward
A: 

This should do the trick:

<a href="contoso.com" class="link"><span class="style1">text will not be displayed</span></a>    

.style1 {
visibility:hidden;
}
Lawrence
A: 
a.link {position:relative;font-size:0;width:x;height:y;}
a.link img {position:absolute;width:100%;height:100%;}

<a href="page.html" class="link">
  Link text
  <img src="mynormalimg.png" onmouseover="this.src='myhoverimg.png'" onmouseout="this.src='mynormalimg.png'" />
</a>

The inline javascript there is possibly bad, but it's just to illustrate. Not sure if img-tags use background-image by default, but in that case it can obviously be done with css. Just don't put a background image on the a-tag, but on the img-tag instead.

Tor Valamo
A: 

If you want to know what google sees on your page you could use lynx. Then you know exactly what you can improve.

streetparade
And if you use Google Webmaster Tools, they recently added a feature that can show what Googlebot sees when it crawls your site.
Roman Stolper