Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่าความสูงขั้นต่ำ (Min Height) ขององค์ประกอบด้วย JavaScript

ใช้คุณสมบัติ minHeight เพื่อกำหนดความสูงขั้นต่ำขององค์ประกอบ เนื้อหาจะไม่ยุบสั้นกว่านี้ (แต่สามารถขยายได้)

ตัวอย่าง

<!DOCTYPE html>
<html>
  <head>
    <style>
      #box {
        width: 300px;
        background-color: gray;
        overflow: auto;
      }
    </style>
  </head>
  <body>
    <p>Click below to set Minimum height.</p>
    <button type="button" onclick="display()">Min Height</button>
    <div id="box">
      <p>This is a div. This is a div. This is a div.</p>
      <p>This is a div. This is a div. This is a div.</p>
      <p>This is a div. This is a div. This is a div.</p>
      <p>This is a div. This is a div. This is a div.</p>
      <p>This is a div. This is a div. This is a div.</p>
    </div>
    <br>
    <script>
      function display() {
        document.getElementById("box").style.minHeight = "400px";
      }
    </script>
  </body>
</html>