4

I have a CSS class for styling buttons. When I apply it to an <input> and an <a> tag, the <a> is a bit smaller than the <input>. This problem occurs in Firefox (33), but in Chrome (38) it looks fine.

Here is a minimal example:

.my-button {
  display: inline-block;
  padding: 1em;
        
  border-radius: 0.2em;
  border: 1px solid #000;
        
  line-height: 1em;
  font-size: 13px;
  text-decoration: none;
    
  background-color: #ccc;
  color: #000;
}
<input class="my-button" type="submit" value="Save">
<a class="my-button" href="#">Cancel</a>

You can see it also here: http://jsfiddle.net/tr4vbrha/4/

eyettea
  • 1,376
  • 2
  • 16
  • 35
  • The answer to the suggested duplicate question is to recreate the buttons with divs using javascript, which I believe is a very dirty solution. – eyettea Nov 10 '14 at 18:15
  • 2
    You read the wrong answer. [Read again](http://stackoverflow.com/a/11605890/1493698). Or if you have trouble finding the correct answer, [see a fiddle](http://jsfiddle.net/nvaj578e/). – Antony Nov 11 '14 at 01:19
  • OK, thanks. This seems to solve it for both Firefox and Chrome, however the `padding: 0 !important;` is not required [see fiddle](http://jsfiddle.net/nvaj578e/1/). Could this be a bug that should be reported to Firefox? – eyettea Nov 11 '14 at 07:57
  • That answer is just an overkill. Just pick the one that works and move on. And no, this is not a bug. The fact that Firefox has its own margin that can be targeted via prefixed selectors are most likely a hack. What we are doing here is just to unhack the hack. – Antony Nov 11 '14 at 09:02

3 Answers3

1

This happens because of a difference in font. The input on windows is Microsoft Sans Serif, while in the a tag it is Times New Roman.

To fix this add the font-family property to the my-button class.

muuk
  • 932
  • 1
  • 7
  • 15
  • I don't think this solves the problem, adding `font-family: Arial;` doesn't change anything: http://jsfiddle.net/tr4vbrha/7/ – eyettea Nov 10 '14 at 16:44
  • I saw the difference in Firefox too and when I added code font-family: "Times New Roman", Georgia, Serif; They look the same. – userDEV Nov 10 '14 at 16:51
  • On Mac OSX Firefox 33.1 and on Ubuntu 14.04 Firefox 33.0 the problem occurs no matter the font-family. I cannot verify for Windows though. In Safari 7.1 it works fine. – eyettea Nov 10 '14 at 17:01
  • Yes I noticed, sorry I thought it would be it – muuk Nov 10 '14 at 18:12
1

This probably is because the box-sizing property of button is different to that of a button. I added this:

input{
    box-sizing: content-box;
}

.my-button{
    min-width: 2.75em;
}

and it worked

eyettea
  • 1,376
  • 2
  • 16
  • 35
0

remove css attribure : display:inline-block see example :demo

.my-button {

    padding: 1em;
    
    border-radius: 0.2em;
    border: 1px solid #000;
    
    line-height: 1em;
    font-size: 13px;
    font-family: Arial;
    text-decoration: none;

    background-color: #ccc;
    color: #000;
}
@media screen and (-webkit-min-device-pixel-ratio:0) {
    .my-button {
        display:inline-block
    }
}
<input class="my-button" type="submit" value="Save">
<a href="#" class="my-button">Cancel</a>
vrajesh
  • 2,935
  • 3
  • 25
  • 40