要设置列之间的间隔,请使用columnGap属性。
您可以尝试运行以下代码,以了解如何使用JavaScript设置列之间的间隔-
<!DOCTYPE html> <html> <body> <p>Click below to create 4 columns and set gap of 30px</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. </div> <script> function display() { document.getElementById("myID").style.columnCount = "4"; document.getElementById("myID").style.columnGap = "30px"; } </script> </body> </html>