相关疑难解决方法(0)

Flexbox:水平和垂直居中

如何使用flexbox在容器中水平和垂直居中div.在下面的例子中,我希望每个数字彼此相同(在行中),它​​们是水平居中的.

.flex-container {
  padding: 0;
  margin: 0;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
row {
  width: 100%;
}
.flex-item {
  background: tomato;
  padding: 5px;
  width: 200px;
  height: 150px;
  margin: 10px;
  line-height: 150px;
  color: white;
  font-weight: bold;
  font-size: 3em;
  text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
<div class="flex-container">
  <div class="row">
    <span class="flex-item">1</span>
  </div>
  <div class="row">
    <span class="flex-item">2</span>
  </div>
  <div class="row">
    <span class="flex-item">3</span>
  </div>
  <div class="row">
    <span class="flex-item">4</span>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

http://codepen.io/anon/pen/zLxBo

html css html5 css3 flexbox

588
推荐指数
9
解决办法
90万
查看次数

标签 统计

css ×1

css3 ×1

flexbox ×1

html ×1

html5 ×1