To center a <button type = "button">
both vertically and horizontally within a <div>
which width is computed dynamically like in your case, this is what to do:
text-align: center;
to the wrapping <div>
: this will center the button whenever you resize the <div>
(or rather the window)For the vertical alignment, you will need to set margin: valuepx;
for the button. This is the rule on how to calculate valuepx
:
valuepx = (wrappingDIVheight - buttonHeight)/2
Here is a JS Bin demo.