如何在 CSS 中將彈性專案與容器居中對齊


 align-items 屬性與值 center 結合使用,可將彈性專案與中間對齊。

示例

你可以嘗試執行以下程式碼來實現中間值

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         .mycontainer {
            display: flex;
            background-color: orange;
            align-items: center;
            height: 150px;
            width: 600px;
         }
         .mycontainer > div {
            background-color: white;
            text-align: center;
            line-height: 40px;
            font-size: 25px;
            width: 100px;
            margin: 5px;
         }
      </style>
   </head>
   <body>
      <h1>Quiz</h1>
      <div class = "mycontainer">
         <div>Q1</div>
         <div>Q2</div>
         <div>Q3</div>
         <div>Q4</div>
      </div>
   </body>
</html>

更新於:06-Jul-2020

117 次瀏覽

開啟您的職業生涯

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.