Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What makes <button> to position inner text in the center(vertically&horizontally)?

Tags:

html

css

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.

enter image description here

like image 982
Websirnik Avatar asked Oct 15 '13 20:10

Websirnik


1 Answers

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;
}
like image 66
Kevin Lynch Avatar answered Sep 18 '22 12:09

Kevin Lynch