Button not center align in Safari

Junaid picture Junaid · Jun 22, 2015 · Viewed 12.8k times · Source

Button not centered align in Safari browser only.

JSFIddle

HTML

<div class="" style=" width: 100%; ">
    <input value="Button" class="center-block" type="submit" style=""/>
</div>

CSS

.center-block {
display: block;
margin-right: auto;
margin-left: auto;
}

Above problem just come in Safari. In Chrome and Firefox it works fine.

Answer

Dmitriy picture Dmitriy · Jun 22, 2015

if you don't set a width for btn:

  1. parent - text-align: center
  2. button child - use display:inline-block instead of display: block

.wrap {
    text-align: center;
}
.center-block {
    display: inline-block;
}
<div class="wrap">
    <input value="Button" class="center-block" type="submit" />
</div>