Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Javascript

จะตั้งค่าความกว้างของคอลัมน์และจำนวนคอลัมน์ด้วย JavaScript ได้อย่างไร


ในการตั้งค่าความกว้างของคอลัมน์และจำนวนคอลัมน์ในการประกาศครั้งเดียว ให้ใช้ คอลัมน์ JavaScript ทรัพย์สิน

ตัวอย่าง

คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อกำหนดความกว้างของคอลัมน์และจำนวนคอลัมน์ด้วย JavaScript -

<!DOCTYPE html>
<html>
   <head>
      <style>
         #myID {
            column-count: 4;
            column-rule: 4px solid yellow;
         }
      </style>
   </head>
   <body>
      <p>Click below to change the column count to 2 and minimum size</p>
      <button onclick="display()">Change Column count and set size</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.columns = "70px 2";
         }
      </script>
   </body>
</html>