Để chia div thành ba cột, dùng thuộc tính columnCount. Đặt số cột và chia div.
Ví dụ
Bạn có thể chạy mã sau để trả về số cột phần tử được chia với JavaScript −
<!DOCTYPE html> <html> <body> <p>Nhấn dưới để tạo 4 cột</p> <button onclick="display()">Cột</button> <div id="myID"> Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. </div> <script> function display() { document.getElementById("myID").style.columnCount = "4"; } </script> </body> </html>