Vertically centering text inside flexbox item

六月ゝ 毕业季﹏ 提交于 2019-12-04 01:40:09

I was able to accomplish vertical centering of your numbers with this:

.flex-item {
  display:flex;
  flex-direction:column;
  justify-content:space-around;
}

If you want something to be vertically centered, set the container to display:flex and then use justify-content to accomplish it. With justify-content you could either set it to space-around or to center. Either will accomplish your goal.

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

Give the flex items display: flex and align-items: center. The flex items contents will now be vertically centered.

body {
  display: flex;
  height: 100vh;
  margin: 0;
}
body > div {
  flex: 1;
  display: flex;
  align-items: center;
  background: #F00;
}
body > div:nth-child(odd) {
  background: #F90;
}
<div>
  <p>This</p>
</div>
<div>
  <p>text</p>
</div>
<div>
  <p>is</p>
</div>
<div>
  <p>vertically</p>
</div>
<div>
  <p>centered</p>
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!