How to vertically align text inside a flexbox?

前端 未结 10 1552
不知归路
不知归路 2020-11-22 09:24

I would like to use flexbox to vertically align some content inside an

  • but not having great success.

    I\'ve checked online and many of the tut

  • 10条回答
    •  独厮守ぢ
      2020-11-22 10:20

      Set the display in li as flex and set align-items to center.

      li {
        display: flex;
      
        /* Align items vertically */
        align-items: center;
      
        /* Align items horizontally */
        justify-content: center;
      
      }
      

      I, personally, would also target pseudo elements and use border-box (Universal selector * and pseudo elements)

      *,
      *::before,
      *::after {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
      }
        
      

    提交回复
    热议问题