TL;DR: It is not possible to recreate the layout created by a <button>
element using CSS. Or at least it is hidden really well.
I tested this by changing the display value to flex on a <button>
and it affected the vertical alignment. Other values like display:block
did not have an effect. It seems that there is no css value for this, it just is the default behavior and there is no way to do it for a div.
Like you, I was looking for an answer to this question. I was trying to find css property which centers vertically content in button. When I almost gave up I decided to leaf through html specification and this is what I found:
If the element is an input element, or if it is a button element and
its computed value for 'display' is not 'inline-grid', 'grid',
'inline-flex', or 'flex', then the element's box has a child anonymous
button content box with the following behaviors:
- The box is a block-level block container that establishes a new
block formatting context (i.e., 'display' is 'flow-root').
- If the box does not overflow in the horizontal axis, then it is
centered horizontally.
- If the box does not overflow in the vertical axis, then it is
centered vertically. Otherwise, there is no anonymous button content box.
https://html.spec.whatwg.org/multipage/rendering.html#button-layout
<p />
margin etc. You can make text centered for example vialine-height
, with flex propertyalign-items: center
, withpadding
, .... – LeapSo far i tried digging through the Chromium user agent stylesheets but was not successful. -webkit-appereance: button also did not do the trick.
That means I looked at the Chromium default styles. – Quass