css中display:flex屬性實現元素垂直置中的代碼

來源:互聯網
上載者:User
這篇文章給大家介紹的內容就是關於css中display:flex屬性實現元素垂直置中的代碼,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

在此之前元素垂直置中我使用的是絕對位置absolute或固定定位fixed

如何用flex實現元素垂直置中呢,父級包括子級

<div  class='itemBox'>    <div>boxboxboxboxboxboxboxboxboxboxbox</div></div> .itemBox{display: flex;justify-content: center;align-items: center;background: #588cfe;width: 100%;height: 100vh;}.itemBox p{background: #ffffff;width: 200px;height: 200px;word-break: break-all;//英文超出盒子不換行問題}
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.