0

I want to replace the text of a url to an image. I am trying following:

HTML:

<div class="img">
    <a href="#">link</a>                    
</div>

CSS:

.img a{
    width: 96px; 
    height: 96px; 
    background: url("image.jpg"); 
    text-indent: -9999px; 
}

It would still show the text. I want the image instead of the text.

PS. I don't want to put the image in the html, ie.

<div class="img">
 <a href="#"><img src="image.jpg" alt="image" /></a>                
</div>
2
  • Maybe post a jsfiddle of what you've done. My site has something just like this and it works fine. Commented Nov 11, 2011 at 10:16
  • what if you set a min-width and min-height in your CSS, and remove the text? Commented Nov 11, 2011 at 10:18

4 Answers 4

1

An anchor tag is by definition an inline element and therefore will not accept height or width declarations.

To obtain your desired effect, use display: inline-block;. (won't work in IE<8 I believe)

.img a{
    display: inline-block;
    width: 96px; 
    height: 96px; 
    background: url("image.jpg"); 
    text-indent: -9999px; 
}
Sign up to request clarification or add additional context in comments.

Comments

0

text-indent applies to block level elements so just add display: block; or display: inline-block; to the .img a CSS (this will also make the width and the height work).

Comments

0

I don't know the exact CSS trick that you should use to get this done.
But as per my knowledge I can make a suggestion.
You cannot have class name as "img" as it is already a HTMl tag. If you write anything for it, that property will be considered for the <img> tag.

Comments

0

Use overflow: hidden with your current style definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.