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

การจัดตำแหน่ง Flex Items ที่ด้านบนของ Container ใน CSS


ใช้คุณสมบัติ align-items พร้อมค่า flex-start เพื่อจัด Flex Items ให้อยู่ด้านบน

คุณสามารถลองรันโค้ดต่อไปนี้เพื่อนำค่า flex-start ไปใช้ได้

ตัวอย่าง

<!DOCTYPE html> <html>    <head>       <style>          .mycontainer {             display: flex;             height: 300px;             background-color: red;             align-items: flex-start;          }          .mycontainer > div {             background-color: white;             text-align: center;             line-height: 60px;             font-size: 30px;             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>Q5</div>       </div>    </body> </html>