tags:

views:

107

answers:

5

We have buttons of many sizes and colors that use background images. There is a label on the background image itself, but we need to keep the button's text in the HTML for usability/accessibility. How do I make the text disappear in all browsers?

Modern browsers are easy, I just used -

color: transparent;

It's Internet Explorer 7 that I can't get to comply. I've tried these CSS properties, and none of them can remove the text completely without destroying my site's layout in the process.

font-size: 0px;
line-height: 0;
text-indent: -1000em; 
display: block;
padding-left: 1000px;

I would very much appreciate any help.

+1  A: 

How do I make the text disappear in all browsers?

I suppoose you want the altarnative text to disappear if the image is loaded.

For this puprpose you can use this:

<INPUT TYPE="image" SRC="images/yourButtongif" HEIGHT="30" WIDTH="100" ALT="Text In Case There Is No Image" />

You can apply additional styles if needed, but this minimum will do the job for you.

Dmytrii Nagirniak
I think he is talking about normal button elements, not images.
Pekka
A: 

If I understand the question correctly, this might work (I don't have IE7 to test on at the moment, so not 100% sure)

For markup like this:

<a href="javascript:return false;" class="button" id="buttonOK"><span
    class="icon">Ok</span></a>

Use this css:

span.icon {
    /*visibility: hidden;*/
    display:block;
    margin-left:-1000;
    width:100px;
}

or this might work depending on your requirements for usability/accessibility:

span.icon {
    visibility: hidden;
}
Dave Paroulek
He works with actual button form elements, I think.
Pekka
+1  A: 

I don't know what users / programs the labels need to be in the HTML for, but if it's for text browsers and such, maybe you could insert a JavaScript that removes the labels onLoad?

JQuery or Prototype would make that very easy.

Pekka
A: 

In some cases you can use the propery "content" to change what is contained in the element, personally though I would use javascript to do it.

Just write blank text into the element.

David
+1  A: 

If the button is an input submit button, use the image

<input type="image" src="/images/some_image.png" />

You can style this with CSS

input[type="image"] {
  border: 1px solid red;
  width: 150px;
  height: 35px;
}

If they are links, Dave provided the answer.

Richard Testani
An input of type image should always have an `alt` attribute specified, just as for an ordinary image tag. Given that the OP is concerned about accessibility, you should add it to your example. Something like `alt="Sign me up"` would completely solve the original problem.
NickFitz