Computer >> Máy Tính >  >> Lập trình >> Javascript

Làm cách nào để đặt khoảng cách giữa các cột bằng JavaScript?


Để đặt khoảng cách giữa các cột, hãy sử dụng columnGap tài sản.

Ví dụ

Bạn có thể thử chạy đoạn mã sau để tìm hiểu cách đặt khoảng cách giữa các cột bằng 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>