【发布时间】:2016-08-27 15:22:43
【问题描述】:
为什么放在flex容器内的按钮使用margin : 0px auto;居中,而放在普通容器内的按钮却不是?
另外,我可以做些什么来使按钮在普通容器中居中(我无法更改我的 HTML,因此我们将不胜感激使用 CSS 解决方案。)
.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 链接:https://jsfiddle.net/r8h3d9wy/1/
【问题讨论】:
标签: html css flexbox centering