當專案未使用主軸上的可用空間時,用 CSS 水平對齊 flex 專案


當專案未使用主軸上的可用空間時,使用 justify-content 屬性水平對齊 flex 專案。

你可以嘗試執行以下程式碼來實現 justify-content 屬性

示例

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         .mycontainer {
            display: flex;
            background-color: blue;
            justify-content: center;
         }
         .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>

更新於: 2020 年 6 月 24 日

104 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.