Why is it that a button placed inside a flex
container is centered by using margin : 0px auto;
, but a button placed inside a normal container is not?
Also, what can I do to center the button in the normal container (I cannot change my HTML, so a CSS solution would be appreciated.)
.flex-container {
display: flex;
background: yellow;
}
.normal-container {
background: green;
}
button {
margin: 0px auto;
}
<div class="flex-container">
<button>Button in flex</button>
</div>
<div class="normal-container">
<button>Button in normal</button>
</div>
jsFiddle link : https://jsfiddle.net/r8h3d9wy/1/