tags:

views:

3858

answers:

6

I'm trying to style my form buttons and I'm experiencing a problem in FireFox that I can't get to the bottom of...

I want to style certain <a />s and <input type="submit" />s to look the same (I have a button background image, using a sliding-doors technique to apply a hover effect.)

This all works great, except in FireFox, the input submit text is slightly lower down than it should be. IE and Safari/Chrome work fine.

alt text

Anyone got any ideas?

Thanks

<div class="buttons">
    <a href="#" class="button btn-small-grey">&laquo Back</a>
    <input type="submit" class="button btn-large-green" value="Save changes" />
</div>

.button
{
    cursor: pointer;
    border: 0;
    background-color: #fff;
    color: #fff;
    font-size: 1.4em;
    font-weight: bold;
    outline: 0;
    font-family: Arial, Verdana, Sans-Serif;
}

a.button
{
    display: block;
    float: left;
    text-align: center;
    text-decoration: none;
    padding: 5px 0 0 0;
    height: 22px;
    margin-right: 1em;
}

.btn-small-grey
{
    height: 27px;
    width: 96px;
    background-position: 0 -81px;
    background-image: url(/assets/images/buttons/buttons-small.gif);
}

.btn-large-green
{
    height: 27px;
    width: 175px;
    background-position: 0px -54px;
    background-image: url(/assets/images/buttons/buttons-large.gif);
}
+1  A: 

I had the same problem and I've solved (only for FF and Safari) by fixing the width but not the height and playing with the values: padding (top and bottom), line-height and if needed setting the vertical-align to middle! However all it's more easy to do if you set all the values (even the font size) in pixel!


EDIT: I think that there isn't a cross-browser solution, because the problem is due to the text rendering of the browsers! To solve completely the problem you could draw a background img with text and apply that image to the link or the button! Even if with this solution you lose in accessibility!

Alternatively you can use conditional CSS statements to improve the layout for each browser!

BitDrink
although i could have missed the magic combination, I've found fiddling with all those things only causes another problem in another browser, and i just chase those round forever!
Andrew Bullock
+3  A: 

I have same problem every time I need to style form buttons. Sorry, quite busy at the moment so only brief description how I usually fix it.

In FF Text is usually a bit lower, exactly like on the image you attached and so then I simply apply "padding-bottom" on the button itself. It moves the text on the button number of pixels up.

The problem is it also moves text in IE and now IE looks a bit off. To fix that I apply "line-height" to the same button with exactly same value as the height of the button. That makes IE to ignore padding completely and positions the text right in the middle. Below is sample HTML code:

<input type="submit" value="SEARCH" class="search"/>

and CSS:

.search
{
    background: transparent url(../images/sprites.gif) no-repeat -310px 0; /* some button image */
    height: 29px;
    width: 104px;   
    border: 0; 

    /* centering text on button */
    line-height: 29px; /* FF will ignore this but works for IE. This value should be same as value of the height property above */
    padding-bottom: 2px; /* IE will ignore but works for FF */
}

Sorry I didn't applied it directly to your code but I'm a bit busy at the moment, hope you got the idea and it helps though.

ps. just checked in IE8 and all above moves text few pixels up. So it means more (endless?) mocking around with padding top/bottom.. I lost my patience now though and I think I'll be putting all this in separate stylesheet from now on that is until I find some fairly easy and universal solution for all this

spirytus
ha! victory! nice one :)
Andrew Bullock
+9  A: 

I found this post because I had resolved this problem a few months ago and when I ran into it again today, I couldn't remember what I'd done. Nice. After poring over my css I finally located the "fix". I can't take credit because I found it on the web somewhere, but hopefully it will be as useful to you as it has been for me:

input::-moz-focus-inner /*Remove button padding in FF*/
{ 
    border: 0;
    padding: 0;
}

I hope this helps.

Shelly Skeens
oo i shall try this on monday, nice one
Andrew Bullock
This is perhaps the simplest solution to the problem I have ever seen! Thanks a lot! My buttons not look identical in IE7, IE8, Firefox 3.6 and Chrome. I added an extra style for the button tag, which I use for buttons with icons attached.
TigerShark
aceness! works nicely
Andrew Bullock
Yes, this drove me nearly crazy for a while. I'm happy to pass it along!
Shelly Skeens
A: 

Brilliant solution Shelly Skeens! It sorts out Firefox while being ignored by the other browsers.

kalengi
you should make this a comment of shelly's answer instead of posting an answer, which clearly isnt an answer, but a comment.
Andrew Bullock
yes, I wanted to do so at the time, but had no capability to comment :(
kalengi
A: 

smart move!! worked for me cheersCr

Craig Muirhead