I'm trying to understand what makes <button>
tag to position text right in the center of the element by default. Horizontal alignment is controlled by the text-align: center
. What controls the vertical alignment?
Here is the fiddle to play with: http://jsfiddle.net/GW9KL/
Here is Chrome default stylesheets for <button>
. Can't see what makes it vertically aligned.
This question intrigued me so I began to investigate. To cut a long story short, in chrome at least, display: -webkit-box;
is applied to button elements. I had to install a developer plugin to see it. i have copy and pasted the styling and applied it to a div. A JSfiddle shows the results
Example http://jsfiddle.net/GW9KL/2/
div {
text-align: center;
color: buttontext;
border: 2px outset buttonface;
background-color: buttonface;
font: -webkit-small-control;
-webkit-appearance: button;
display: -webkit-box;
-webkit-box-pack: center;
-webkit-box-align: center;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With