×

Save Your Code

If you click the save button, your code will be saved, and you get an URL you can share with others.

By clicking the "Save" button you agree to our terms and conditions.

Report Error

×

Save to Google Drive

If you have a Google account, you can save this code to your Google Drive.

Google will ask you to confirm Google Drive access.

×

Open from Google Drive

If you have saved a file to Google Drive, you can open it here:

Result Size: 625 x 571
x
 
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
  height: 250px;
  width: 400px;
  padding: 10px;
  margin: 15px;
  border: 5px solid red;
  background-color: lightblue;
  overflow: auto;
}
#myDIV2 {
  height: 250px;
  width: 400px;
  padding: 10px;
  margin: 15px;
  border: 5px solid red;
  background-color: lightblue;
}
#content {
  height: 800px;
  width: 2000px;
  background-color: lightyellow;
}
</style>
</head>
<body>
<p>In this example, the child element (#content) inside the first div is bigger than div's height and width 
(the child is 800x2500 while its parent is 250x400), so we have added a scrollbar.</p>
<p>Click the button to get the clientHeight, offsetHeight, clientWidth and offsetWidth of div.</p>
<button onclick="myFunction()">Try it</button>
<p>Notice how the scrollbar in the first div "steals" some of div's right and bottom padding, which results in a lower return value for clientHeight and clientWidth in that div, compared to the other one. The offsetHeight and offsetWidth is not affected by this.</p>
<div id="myDIV">
  <div id="content"></div>
</div>
×

Report a Problem: