tags:

views:

36

answers:

3

Hello all,

#tab-ver.tab {
    background: url(../images/16by16.png) no-repeat center center;
    text-indent: -10000em;
    height: 16px;
    width: 16px;
    padding: 4px 1px;
    margin-right: 1px;
    margin-left: 50px;
}

<div id="tab-ver" class="tab"><a href="http://www.yahoo.com"&gt;English&lt;/a&gt;&lt;/div&gt;

The problem of above script is that the a link doesn't work at all. If the user clicks the 16by16.png image, the user is not redirected to yahoo.com.

However to fix this problem?

Thank you

// update001//
I have tried the following suggestion:

#tab-ver.tab {
    text-indent: -10000em;
}
#tab-ver.tab a{
    background: url(../images/16by16.png) no-repeat center center;
    height: 16px;
    width: 16px;
    padding: 4px 1px;
    margin-right: 1px;
    margin-left: 50px;
    display: block;
}

It works for my original problem. However, the displayed image now is offset to bottom of the horizontal menu. It is caused by 'display: block'. However, if I remove 'display:block', then the image will be invisible.

thank you

// update 1 //

Based on the suggestion, the following script works best for me

#tab-en-ver.tab a {
    background: url(../images//16by16.png) no-repeat center center;
    height: 16px;
    width: 16px;
    padding: 4px 1px;
    margin-right: 1px;
    margin-left: 50px;
    text-indent: -10000em;
}

However, this suggestion does have one problem. The text 'English' mixes with the image. I cannot figure out how to remove the text 'English' from a link.

by adding the following extra rule will cause the image disappear.

#tab-ver.tab {
 text-indent: -10000em; 
}

any idea?

+3  A: 

Give that CSS to the <a> instead. Add a display: block so it'll display as a block-level element like the <div>. The <div> will expand to fit the <a>.

EDIT: try inline-block instead and see if it helps.

#tab-ver.tab a {
    display: inline-block;
    background: url(../images/16by16.png) no-repeat center center;
    text-indent: -10000em;
    height: 16px;
    width: 16px;
    padding: 4px 1px;
    margin-right: 1px;
    margin-left: 50px;
}
BoltClock
Or just use the `img` tag - depending on what `16x16.png` is, of course
Yi Jiang
Hello BlotClock, the #tab-ver is one of the horizontal menu I have used for the page. After I adopt your suggestion, the English appears together with image. Any fix? thank you
q0987
+1 good solution. However it will increase your click-able area with the padding so if that is not what you want, you will have to put the padding on the `div`.
jeroen
@q0987: if you did it with your question's example and the text disappeared as intended, you can move the `text-indent: -10000em;` to `#tab-ver.tab` instead.
BoltClock
Hello BoltClock, your answer solves my problem however it causes another problem. As I said, #tab-ver is one of my horizontal menu. AFter I use 'display: block', the image is visible however, its location is offset. I tried to remove 'display: block', it ends up with an invisible image. I really need a solution without destroying my original horizontal menu layout. thank you
q0987
@BlotClock, I have tried the inline-block, it doesn't work for me. thx
q0987
Is the layout still messed up right now?
BoltClock
+1  A: 

You can have the a tag fill up the div by using:

a {
    display: block;
    height: 16px;
}

You can then also remove the height from the div as it will grow automatically.

jeroen
Hello jeroen, 1> I want to hide the text 2> I want to make the image clickable. 3> the DIV is one of the horizontal menu on the page. thank you
q0987
What happens when you try my answer?
jeroen
@jeroen, when I use 'display: block', it breaks my horizontal menu layout. thank you
q0987
+1  A: 

If you want the text ("English") to be hidden, than you have to use <img/> tag, with an alt attribute, something like:

<img src="english-flag.png" alt="English" />

You can also use some CSS hacks, but:

  1. What for? It's so easy to do it with plain HTML!
  2. Those are hacks, so they may work or not in different browsers.

One of such hacks can be to set a background to the <a/> element, to offset the text, to set the overflow to hidden, and to set fixed width:

a{
    padding-left:16px;
    overflow:hidden;
    display:block;
    width:16px;
    height:16px;
    url(../images/16by16.png) no-repeat left top;}

<a href="...">English</a>
MainMa
Hello MainMa, where should I put this IMG? thank you
q0987
@Mainma - They're not 'hacks' by any definition of the word - image replacement is a valid technique that's cross-browser compatible and widely used
Yi Jiang
Hello MainMa, please check this image http://i52.tinypic.com/245hax1.png As you can see when the mouse hover over the image, there are white background show up. do you know how to fix this problem? thank you
q0987
@MainMa, pls ignore my comments. I have found the fix. thx
q0987