คุณสมบัติ HTML DOM Style flexDirection ใช้เพื่อกำหนดหรือส่งคืนทิศทางของตำแหน่งขององค์ประกอบดิ้น
ต่อไปนี้เป็นไวยากรณ์สำหรับ −
การตั้งค่าคุณสมบัติ flexDirection -
object.style.flexDirection = "row|row-reverse|column|column-reverse|initial|inherit"
อธิบายคุณสมบัติข้างต้นดังนี้ −
| ค่า | คำอธิบาย |
|---|---|
| แถว | แสดงรายการ flex เป็นแถวในแนวนอนและเป็นค่าเริ่มต้น |
| row-reverse | แสดงรายการ flex ในแนวนอนแต่ในลำดับย้อนกลับของแถว |
| คอลัมน์ | แสดงรายการ flex เป็นคอลัมน์ในแนวตั้ง |
| column-reverse | แสดงรายการ flex ในแนวตั้งแต่ในลำดับย้อนกลับของคอลัมน์ |
| ค่าเริ่มต้น | การตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | การสืบทอดค่าคุณสมบัติหลัก |
ให้เราดูตัวอย่างคุณสมบัติ flexDirection -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
#demo {
box-shadow: 0 0 0 3px #a323c3;
display: flex;
flex-direction: column-reverse;
}
#demo div {
margin: auto;
border: thin solid green;
}
</style>
<script>
function changeFlexDirection() {
document.getElementById("demo").style.flexDirection="row-reverse";
document.getElementById("Sample").innerHTML="The flex direction for the container div is changed to row-reverse";
}
</script>
</head>
<body>
<div id="demo">
<div>1 <img src="https://www.tutorialspoint.com/images/3d.png"></div>
<div>2 <img src="https://www.tutorialspoint.com/images/blockchain.png"></div>
<div>3 <img src="https://www.tutorialspoint.com/images/css.png"></div>
<div>4 <img src="https://www.tutorialspoint.com/images/reactjs.png"></div>
</div>
<p>Change the above container div flex direction by clicking the below button</p>
<button onclick="changeFlexDirection()">Change Flex Direction</button>
<p id="Sample"></p>
</body>
</html> ผลลัพธ์

เมื่อคลิกปุ่ม “เปลี่ยนทิศทางการโค้งงอ ปุ่ม −
