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

คุณสมบัติ columnRule ของ HTML DOM Style: Shorthand กฎคอลัมน์

คุณสมบัติ columnRule เป็น shorthand สำหรับกำหนดหรือดึงค่าของเส้นกั้นระหว่างคอลัมน์ (Column Rule) ครบทั้ง 3 คุณสมบัติ: columnRuleWidth, columnRuleStyle, columnRuleColor

ไวยากรณ์ (Syntax)

object.style.columnRule = "column-rule-width column-rule-style column-rule-color|initial|inherit"

พารามิเตอร์

พารามิเตอร์คำอธิบาย
columnRuleWidthความกว้างเส้นกั้น (medium = ค่าเริ่มต้น)
columnRuleStyleรูปแบบเส้นกั้น (none = ค่าเริ่มต้น)
columnRuleColorสีเส้นกั้น (สีขององค์ประกอบ = ค่าเริ่มต้น)
initialตั้งค่ากลับเป็นค่าเริ่มต้น
inheritสืบทอดจากพาเรนต์

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

<!DOCTYPE html>
<html>
<head>
<style>
  #DIV1 {
    column-count: 4;
    column-rule: 4px dashed darkolivegreen;
  }
</style>
<script>
  function changeColumnRule() {
    document.getElementById("DIV1").style.columnRule = "10px solid red";
    document.getElementById("Sample").innerHTML = "คุณสมบัติ column rule ถูกปรับเปลี่ยนแล้ว";
  }
</script>
</head>
<body>
<div id="DIV1">
  <img src="https://www.tutorialspoint.com/images/Swift.png"><br/>
  <img src="https://www.tutorialspoint.com/images/xamarian.png"><br/>
  <img src="https://www.tutorialspoint.com/images/pl-sql.png"><br/>
  <img src="https://www.tutorialspoint.com/images/asp-net.png"><br/>
  <img src="https://www.tutorialspoint.com/images/powerbi.png"><br/>
  <img src="https://www.tutorialspoint.com/images/Tableau.png"><br/>
  <img src="https://www.tutorialspoint.com/images/Big-Data-Analytics.png"><br/>
  <img src="https://www.tutorialspoint.com/images/microsoftproject.png">
</div>
<p>คลิกปุ่มเพื่อเปลี่ยนคุณสมบัติ column rule ของ div ด้านบน</p>
<button onclick="changeColumnRule()">เปลี่ยน Column Rule</button>
<p id="Sample"></p>
</body>
</html>

ผลลัพธ์

ก่อน: เส้นกั้น 4px dashed darkolivegreen
หลัง: เส้นกั้น 10px solid red

คุณสมบัติ Longhand ที่เกี่ยวข้อง

  • columnRuleWidth - ความกว้างเส้นกั้น
  • columnRuleStyle - รูปแบบเส้นกั้น (none, solid, dashed, dotted, double, groove, ridge, inset, outset)
  • columnRuleColor - สีเส้นกั้น

คุณสมบัติ Multi-column อื่นๆ

คุณสมบัติคำอธิบาย
columnCountจำนวนคอลัมน์
columnGapระยะห่างระหว่างคอลัมน์
columnWidthความกว้างคอลัมน์
columnsShorthand: columnWidth + columnCount
columnSpanการข้ามคอลัมน์ขององค์ประกอบ
columnFillการกระจายเนื้อหา (auto, balance)

เงื่อนไขการทำงาน

  • ต้องมี column-count > 1 หรือ column-width กำหนดไว้
  • ทำงานกับ block containers (div, article, section ฯลฯ)
  • รองรับในเบราว์เซอร์สมัยใหม่ทั้งหมด