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

CSS flex-direction: row-reverse - เรียง Flex Items ขวาไปซ้าย

ใช้ flex-direction: row-reverse เรียง Flex Items แนวนอนจากขวาไปซ้าย (Right to Left)

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
    <style>
        .mycontainer {
            display: flex;
            flex-direction: row-reverse;
            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>Q4</div>
        <div>Q5</div>
        <div>Q6</div>
    </div>
</body>
</html>

ค่าของ flex-direction:

  • row (Default) — ซ้ายไปขวา
  • row-reverse — ขวาไปซ้าย
  • column — บนลงล่าง
  • column-reverse — ล่างขึ้นบน