运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
前往 Spaces
<!DOCTYPE html> <html> <style> #myDIV { height: 250px; width: 400px; padding: 10px; margin: 15px; border: 5px solid red; background-color: lightblue; } </style> <body> <h1>The Element Object</h1> <h2>The offsetHeight and offsetWidth Properties</h2> <div id="myDIV"> <b>Information about this div:</b><br> Height: 250px<br> Width: 400px<br> Padding: 10px<br> Margin: 15px<br> Border: 5px<br> <p id="demo"></p> </div> <script> const element = document.getElementById("myDIV"); let text = "Height including padding and border: " + element.offsetHeight + "px<br>"; text += "Width including padding and border: " + element.offsetWidth + "px"; document.getElementById("demo").innerHTML = text; </script> </body> </html>