Javascript DOM CSS Style marginBottom Property compare to paddingBottom

Introduction

Difference between marginBottom and paddingBottom:

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
div {/*from w  w w .ja v  a 2  s.  com*/
  border: 1px solid #FF0000;
}
</style>
</head>
<body>

<div id="myDiv">This is some text.</div>
<br>
<button type="button" onclick="changeMargin()">Change bottom margin of the div element</button>
<br>
<br>

<div id="myDiv2">This is some text.</div>
<br>
<button type="button" onclick="changePadding()">Change bottom padding of the div element</button>

<script>
function changeMargin() {
  document.getElementById("myDiv").style.marginBottom = "100px";
}

function changePadding() {
  document.getElementById("myDiv2").style.paddingBottom = "100px";
}
</script>

</body>
</html>



PreviousNext

Related