คุณสมบัติ 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 | ความกว้างคอลัมน์ |
| columns | Shorthand: columnWidth + columnCount |
| columnSpan | การข้ามคอลัมน์ขององค์ประกอบ |
| columnFill | การกระจายเนื้อหา (auto, balance) |
เงื่อนไขการทำงาน
- ต้องมี
column-count> 1 หรือcolumn-widthกำหนดไว้ - ทำงานกับ block containers (div, article, section ฯลฯ)
- รองรับในเบราว์เซอร์สมัยใหม่ทั้งหมด