如何使用 JavaScript 設定元素邊距?
在 JavaScript 中使用 margin 屬性來設定邊距。你可以嘗試執行以下程式碼,使用 JavaScript 設定元素邊距 −
示例
<!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>
廣告