OK, this is most probably basic web development 101, but can someone explain to me why these two buttons aren't the same size? The only difference is that the first button is using the em
unit and the second button is using px
.
jsFiddle (Demo)
HTML
<button type="button" class="em">em</button>
<button type="button" class="px">px</button>
CSS
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-size: 100%;
}
.em {
position: relative;
width: 9.375em; /* 150px */
height: 3.125em; /* 50px */
background: #18a397;
text-align: center;
margin: 1em;
box-sizing: content-box;
}
.px {
position: relative;
width: 150px; /* 9.375em */
height: 50px; /* 3.125em */
background: #18a397;
text-align: center;
margin: 16px;
}
If I change the first button to a div instead, for example like this: <div class="em">em</div>
the element gets resized to the same size as the second button.
So, for some reason, there's a difference between using px
and em
together with <button>
- but I don't know what and why ...?
Tested in: Safari 7, Chrome 31.0.1650.63 and Firefox 26.0.