views:

12132

answers:

12

I am currently styling an input type='button' element using something like:

background-url: url(someimage); color: transparent; background-color: transparent;

-the point is i want the button to show as an image, and i want the value-text to NOT display on top of it. This works fine for Firefox as expected. However, on IE6 & IE7 i can still see the text.

I have tried all sorts of tricks to get the text to not display and still no joy. Has anyone got a solution to make IE behave?

(i am constrained to use type=button because this is a drupal form and its form api doesn't support image-type)

+6  A: 

Why are you including the value attribute at all? From memory, you don't need to specify it (although HTML standards may say you do - not sure). If you do need a value attribute, why not just state value=""?

If you do take this approach, your CSS will need additional properties for the height and width of the background image.

Phil.Wheeler
*head smack* -- Alright - this actually works for me .. and I'd already been setting width and height . so tnx !
Scott Evernden
It should be noted that this makes the button entirely useless for sight-impaired users.
ceejayoz
That's actually a very valid point. You could work around this by adding a title and alt attribute to the button, couldn't you?
Phil.Wheeler
+5  A: 

Have you tried setting the text-indent property to something like -999em? That's a good way to 'hide' text.

Or you can set the font-size to 0, which would work too.

http://www.productivedreams.com/ie-not-intepreting-text-indent-on-submit-buttons/

Ryan Doherty
yes i tried this and the buttons disappeared .. font-size = 0 still shows a dot
Scott Evernden
text-indentation doesn't work in IE 7 and older - whole button gets indented, not only text
zappan
+7  A: 

I was having the opposite problem (worked in IE, but not FF). For IE, you need to add left padding, and for FF, you need to add transparent color. So here is our combined solution for a 16px x 16px icon button:

input.iconButton
{
    font-size: 1em;
    color: transparent; /* Fix for FF */
    border-style: none;
    border-width: 0;
    padding: 0 0 0 16px !important; /* Fix for IE */
    text-align: left;
    width: 16px;
    height: 16px;
    line-height: 1 !important;
    background: transparent url(../images/button.gif) no-repeat scroll 0 0;
    overflow: hidden;
    cursor: pointer;
}
jsalwen
This doesn't work for me in IE7.
Chris S
A: 

Applying "font-size: 0.1px;" to the button works for me in FF, IE6&IE7, Safari. None of the other solutions I've found worked across all of the browsers.

+2  A: 

well:

font-size: 0; line-height: 0;

work awesome for me!

Nice one! This seems like the least disruptive workaround for IE.
Tobias Cohen
+3  A: 

I use

button {text-indent:-9999px;}
* html button{font-size:0;display:block;line-height:0}  /* ie6 */
*+html button{font-size:0;display:block;line-height:0}  /* ie7 */
Emily
+1 `line-height:0` did the trick for me in IE. Thanks.
Liam
A: 
works in FF3, IE 8, IE 8 compatablitiy mode, Opera, Safari

*note table cell containing this has padding:0 and text-align:center



background: none;

background-image: url(../images/image.gif);

background-repeat:no-repeat;

overflow:hidden;

border: NONE;

width: 41px; /*width of image*/

height: 19px; /*height of image*/

font-size: 0;

padding: 0 0 0 41px;

cursor:pointer;
A: 

overflow:hidden and padding-left are working fine for me.

For Firefox:

width:12px;
height:20px;
background-image:url(images/arrow.gif);
color:transparent;
overflow:hidden;
border:0;

For the IEs:

padding-left:1000px;
Niels
A: 

padding-left:1000px; rocks! thanks a lot.

Zillion
A: 

color:transparent; and then any text-transform property does the trick too.

so

color: transparent; text-transform: uppercase;

rufus2021
A: 

color:transparent; -- For FF
*padding-left:1000px ; --- FOR IE6,IE7

Thanks

Somu
A: 

Sorry to sound stupid... but how can adding a padding help?

franz