Html element is not vertically centered with flex center

前端 未结 2 1396
粉色の甜心
粉色の甜心 2021-01-25 18:27

Thats my fiddle: http://jsfiddle.net/atav8vzz/4/

Why is the html element with class \"vertical-align\" not vertically centered?

相关标签:
2条回答
  • 2021-01-25 18:49

    Just add justify-content: center; to your code:

    .vertical-align {
        display: ms-flex;
        display: flex;
        align-items: center;
        justify-content: center;  
    }
    
    0 讨论(0)
  • 2021-01-25 19:11

    I guess it depends what you're trying to achieve here. align-items does so vertically. Where as justify-content does so horizontally.

    See this example. I have given the <h3> height, to illustrate that it is centred vertically.

    0 讨论(0)
提交回复
热议问题