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

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

ใช้คุณสมบัติ shorthand margin เพื่อกำหนดขอบทั้ง 4 ด้านพร้อมกัน รูปแบบ: top right bottom left (ตามเข็มนาฬิกา)

ตัวอย่าง

<!DOCTYPE html>
<html>
  <body>
    <button type="button" onclick="display()">Set all four margins</button>
    <p id="myID">This is demo text.</p>
    <script>
      function display() {
        document.getElementById("myID").style.margin = "30px 20px 40px 40px";
      }
    </script>
  </body>
</html>