Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

จัดแนวรายการ flex ในแนวนอนเมื่อรายการไม่ได้ใช้พื้นที่ว่างทั้งหมดบนแกนหลักด้วย CSS


ใช้ justify-content คุณสมบัติเพื่อจัดแนวรายการดิ้นในแนวนอนเมื่อรายการไม่ได้ใช้พื้นที่ว่างทั้งหมดบนแกนหลัก

คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้คุณสมบัติ 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>