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

คุณสมบัติ columnRuleStyle ของ HTML DOM Style: รูปแบบเส้นกั้นคอลัมน์

คุณสมบัติ columnRuleStyle ใช้สำหรับกำหนดหรือดึงค่ารูปแบบของเส้นกั้นระหว่างคอลัมน์

ไวยากรณ์ (Syntax)

object.style.columnRuleStyle = "none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset|initial|inherit"

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

ค่าคำอธิบาย
noneไม่มีเส้นกั้น (ค่าเริ่มต้น)
hiddenเหมือน none แต่จองพื้นที่ (โปร่งใส)
dottedเส้นจุด
dashedเส้นขีด
solidเส้นทึบ
doubleเส้นคู่
groove3D ร่อง
ridge3D ฉุ้ม
inset3D ฝังเข้า
outset3D โผล่ขึ้น
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 changeColumnRuleStyle() {
    document.getElementById("DIV1").style.columnRuleStyle = "dashed";
    document.getElementById("Sample").innerHTML = "รูปแบบเส้นกั้นคอลัมน์ถูกเปลี่ยนเป็น dashed แล้ว";
  }
</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="changeColumnRuleStyle()">เปลี่ยน Column Rule Style</button>
<p id="Sample"></p>
</body>
</html>

ผลลัพธ์

ก่อน: เส้นกั้น solid สีฟ้าอ่อน
หลัง: เส้นกั้น dashed สีฟ้าอ่อน

⚠️ ข้อผิดพลาดในตารางค่าเดิม (Fixed)

ตารางเดิมมีค่า insert ซึ่งผิด - ค่าที่ถูกต้องคือ inset - ได้แก้ไขแล้ว

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

  • columnRuleWidth - ความกว้าง
  • columnRuleColor - สี
  • columnRule - Shorthand (width, style, color)

การใช้งานร่วมกับ column-gap

.multi-col {
  column-count: 3;
  column-gap: 2rem;
  column-rule: 1px dashed #999;  /* width style color */
}

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

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