I assumed margin
is the space between parent element and itself since long time ago. But I think it is not true. Please check below short HTML with CSS.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Box Model</title>
<style type="text/css">
body {
background-color: #ccc;
}
header {
text-align: center;
text-decoration: underline;
font-weight: bold;
}
#container {
background-color: grey;
width : 400px;
height : 400px;
}
#container .box {
background-color: slategrey;
width : 200px;
height : 200px;
color : #fff;
border: 5px solid navy;
margin-top: 50px;
margin-left:50px;
padding-top:20px;
padding-left:20px;
}
</style>
</head>
<body>
<header>Box Model Example</header>
<section>
<div id="container">
<div class="box">Content</div>
</div>
</section>
</body>
</html>
You will see the output as below screenshoot.
My margin-top:50px;
is not the space between parent elment container and element box. How could I add the space(from above) between these two elements ?