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

คุณสมบัติ flexFlow ของ Style ใน HTML DOM


คุณสมบัติ flexFlow ของ Style ใน HTML DOM เป็น shorthand property ที่ใช้กำหนด flexDirection และ flexWrap พร้อมกันในคำสั่งเดียว ยอมรับค่าในลำดับเดียวกัน

รูปแบบการใช้งาน (Syntax)

การตั้งค่า flexFlow property:

object.style.flexFlow = "flex-direction flex-wrap|initial|inherit"

คุณสมบัติทั้งสองมีรายละเอียดดังนี้:

ค่า (Value)คำอธิบาย (Description)
flex-directionใช้ระบุทิศทางของ flexible items ค่าที่เป็นไปได้: row, row-reverse, column, column-reverse, initial, inherit. ค่าเริ่มต้นคือ row
flex-wrapใช้ระบุว่า flexible items ควร wrap หรือไม่ ค่าที่เป็นไปได้: nowrap, wrap, wrap-reverse, initial, inherit. ค่าเริ่มต้นคือ nowrap
initialตั้งค่าคุณสมบัติเป็นค่าเริ่มต้น
inheritสืบทอดค่าจากเอลิเมนต์พาเรนต์

ตัวอย่างการใช้งาน

<!DOCTYPE html>
<html>
<head>
<style>
  #demo {
    width: 600px;
    height: 190px;
    border:1px solid black;
    display: flex;
    flex-flow: row-reverse nowrap;
  }
  #demo div {
    width:100px;
    height:100px;
  }
</style>
<script>
  function changeFlexFlow() {
    document.getElementById("demo").style.flexFlow="row wrap";
    document.getElementById("Sample").innerHTML="The flex flow property is now set to row wrap";
  }
</script>
</head>
<body>
  <div id="demo">
    <div><img src="https://www.tutorialspoint.com/images/css.png"></div>
    <div>1</div>
    <div><img src="https://www.tutorialspoint.com/images/Swift.png"></div>
    <div>2</div>
    <div><img src="https://www.tutorialspoint.com/images/reactjs.png"></div>
    <div>3</div>
    <div><img src="https://www.tutorialspoint.com/images/blockchain.png"></div>
    <div>4</div>
    <div><img src="https://www.tutorialspoint.com/images/3d.png"></div>
    <div>5</div>
  </div>
  <p>เปลี่ยน flex flow property ของ container div ด้านบนโดยคลิกปุ่มด้านล่าง</p>
  <button onclick="changeFlexFlow()">Change Flex Flow</button>
  <p id="Sample"></p>
</body>
</html>

ผลลัพธ์

คุณสมบัติ flexFlow ของ Style ใน HTML DOM

เมื่อคลิกปุ่ม "Change Flex Flow":

คุณสมบัติ flexFlow ของ Style ใน HTML DOM