หากต้องการแบ่ง div เป็นสามคอลัมน์ ให้ใช้คุณสมบัติ columnCount ตั้งค่าจำนวนคอลัมน์และแบ่ง div
ตัวอย่าง
คุณสามารถลองรันโค้ดต่อไปนี้เพื่อคืนค่าจำนวนคอลัมน์ที่องค์ประกอบจะถูกแบ่งด้วย JavaScript −
<!DOCTYPE html> <html> <body> <p>Click below to create 4 columns</p> <button onclick="display()">Columns</button> <div id="myID"> This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. </div> <script> function display() { document.getElementById("myID").style.columnCount = "4"; } </script> </body> </html>