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

คุณสมบัติ columnRuleWidth ของ HTML DOM Style: ความกว้างเส้นกั้นคอลัมน์

คุณสมบัติ columnRuleWidth ใช้สำหรับกำหนดหรือดึงค่าความกว้างของเส้นกั้นระหว่างคอลัมน์ (Column Rule)

ไวยากรณ์ (Syntax)

object.style.columnRuleWidth = "medium|thin|thick|length|initial|inherit"

ค่าที่รองรับ

ค่าคำอธิบาย
thinเส้นบาง (~1px)
mediumเส้นกลาง (ค่าเริ่มต้น ~3px)
thickเส้นหนา (~5px)
lengthระบุความกว้างด้วยหน่วย (px, em, rem) แนะนำ
initialตั้งค่ากลับเป็นค่าเริ่มต้น
inheritสืบทอดจากพาเรนต์

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

<!DOCTYPE html>
<html>
<head>
<style>
  #DIV1 {
    padding: 5px;
    column-count: 5;
    column-rule-width: 9px;
    column-rule-color: lightblue;
    column-rule-style: solid;
  }
</style>
<script>
  function changeColumnRuleWidth() {
    document.getElementById("DIV1").style.columnRuleWidth = "3px";
    document.getElementById("Sample").innerHTML = "ความกว้างเส้นกั้นคอลัมน์ถูกลดลงเป็น 3px แล้ว";
  }
</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"><br/>
  <img src="https://www.tutorialspoint.com/images/QlikView.png"><br/>
  <img src="https://www.tutorialspoint.com/images/hadoop.png">
</div>
<p>คลิกปุ่มเพื่อเปลี่ยนความกว้างเส้นกั้นคอลัมน์ของ div ด้านบน</p>
<button onclick="changeColumnRuleWidth()">เปลี่ยน Column Rule Width</button>
<p id="Sample"></p>
</body>
</html>

ผลลัพธ์

ก่อน: เส้นกั้นกว้าง 9px
หลัง: เส้นกั้นกว้าง 3px

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

คุณสมบัติคำอธิบายLonghand
columnRuleShorthand: width, style, color-
columnRuleWidthความกว้างเส้นกั้น✓
columnRuleStyleรูปแบบเส้นกั้น✓
columnRuleColorสีเส้นกั้น✓

รูปแบบเส้นกั้น (columnRuleStyle values)

  • none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset

การใช้งานร่วมกับ columnGap

.multi-col {
  column-count: 3;
  column-gap: 2rem;           /* ระยะห่าง */
  column-rule: 2px solid #ccc; /* เส้นกั้น */
}

/* เส้นกั้นอยู่ตรงกลาง column-gap */

หมายเหตุ

  • ต้องมี column-rule-style ไม่ใช่ none ถึงจะเห็นเส้น
  • หลีกเลี่ยง thin/medium/thick ใช้ px/em/rem แทน
  • เส้นกั้นไม่ส่งผลต่อ layout (ไม่นับใน column-gap)

การรองรับเบราว์เซอร์

รองรับ Chrome 50+, Firefox 52+, Safari 10+, Edge 12+ (ไม่รองรับ IE)