<!DOCTYPE html>
<html>
<style>
#myDIV {
height: 250px;
width: 400px;
padding: 10px;
margin: 15px;
border: 5px solid red;
background-color: lightblue;
}
</style>
<body>
<h1>Element 对象</h1>
<h2>offsetHeight 和 offsetWidth 属性</h2>
<div id="myDIV">
<b>有关此 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 = "包括内边距和边框的高度:" + element.offsetHeight + "px<br>";
text += "包括内边距和边框的宽度:" + element.offsetWidth + "px";
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>