คุณสมบัติ HTML DOM Style columnCount ใช้เพื่อกำหนดจำนวนคอลัมน์ที่จะแบ่งองค์ประกอบ
ต่อไปนี้เป็นไวยากรณ์สำหรับ −
การตั้งค่าคุณสมบัติ columnCount -
object.style.columnCount = "number|auto|initial|inherit"
คุณสมบัติข้างต้นมีคำอธิบายดังนี้:
| ค่า | คำอธิบาย |
|---|---|
| หมายเลข | สำหรับกำหนดจำนวนคอลัมน์ที่จะแบ่งเนื้อหาขององค์ประกอบ |
| อัตโนมัติ | จำนวนคอลัมน์กำหนดโดยคุณสมบัติอื่นเช่น “column-width” นี่คือค่าเริ่มต้นของคุณสมบัติ |
| เริ่มต้น | สำหรับการตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | การสืบทอดค่าคุณสมบัติหลัก |
ให้เราดูตัวอย่างสำหรับคุณสมบัติ columnCount -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
div {
height: 120px;
column-count: 2;
border: 2px solid black;
background-color: mediumvioletred;
}
div > div {
background-color: yellow;
}
</style>
<script>
function changeColumnCount(){
document.getElementsByTagName("div")[0].style.columnCount="4";
document.getElementById("Sample").innerHTML="The column count is now increased to 4";
}
</script>
</head>
<body>
<div id="DIV1">
<div></div>
</div>
<p>Change the above div column count property by clicking the below button</p>
<button onclick="changeColumnCount()">Change Column Count</button>
<p id="Sample"></p>
</body>
</html> ผลลัพธ์

เมื่อคลิกที่ “เปลี่ยนจำนวนคอลัมน์” ปุ่ม −
