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

วิธีตั้งค่าขอบล่าง (Bottom Margin) ขององค์ประกอบด้วย JavaScript

ใช้คุณสมบัติ marginBottom เพื่อกำหนดระยะห่างจากขอบล่างขององค์ประกอบ

ตัวอย่าง

<!DOCTYPE html>
<html>
  <body>
    <p id="myID">This is demo text.</p>
    <button type="button" onclick="display()">Set bottom margin</button>
    <script>
      function display() {
        document.getElementById("myID").style.marginBottom = "95px";
      }
    </script>
  </body>
</html>