CSS Flex Box: How to vertically align “flex items” to middle without losing flex item height?

后端 未结 4 668
野性不改
野性不改 2020-12-31 11:03

Currently my \"flex\" items look like this (vertically aligned: top)...

 _____________________________________
   1

 _____________________________________
          


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 12:04

    Your problem is not really related to the so-called flex-box, in fact what you want to align is the content of the div (not the div), so just use some trick to align it normarlly. Here is one of the tricks:

    div:before {
      content:'';
      height:100%;
      display:inline-block;
      vertical-align:middle;
    }
    

    Demo.

提交回复
热议问题