How to vertically align text inside a flexbox?

前端 未结 10 1246
不知归路
不知归路 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:03

      Using display: flex you can control the vertical alignment of HTML elements.

      .box {
        height: 100px;
        display: flex;
        align-items: center; /* Vertical */
        justify-content: center; /* Horizontal */
        border:2px solid black;
      }
      
      .box div {
        width: 100px;
        height: 20px;
        border:1px solid;
      }
      Hello

      World

    提交回复
    热议问题