使用 CSS 設定 flex 專案的初始長度


使用 flex-basis CSS 屬性設定 flex 專案的長度。

示例

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

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         .mycontainer {
            display: flex;
            background-color: orange;
         }
         .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 style = "flex-basis: 350px">Q4</div>
         <div>Q5</div>
         <div>Q6</div>
         <div>Q7</div>
         <div>Q8</div>
         <div>Q9</div>
      </div>
   </body>
</html>

更新日期: 2020 年 7 月 4 日

92 次瀏覽

開啟您的 職業生涯

完成培訓課程並獲得認證

入門
廣告