如何使用 JavaScript 设置元素的左内边距?
在 JavaScript 中使用 paddingLeft 属性设置左内边距。您可以尝试运行以下代码,使用 JavaScript 返回元素的左内边距 −
示例
<!DOCTYPE html> <html> <head> <style> #box { border: 2px solid #FF0000; width: 150px; height: 70px; } </style> </head> <body> <div id = "box">This is demo text.</div> <br><br> <button type = "button" onclick = "display()">Left padding</button> <script> function display() { document.getElementById("box").style.paddingLeft = "100px"; } </script> </body> </html>
广告