0

Literally spent hours trying to find out why this margin would keep protruding outside the parent container. I diagnosed the issue was when I removed its border, any CSS experts please lend me a hand please! Here are the two pieces of code, just remove the border on the div tag and see the margin protrudes the div container. I want to have a margin without the border but want to keep the margin enclosed within the parent, why is is happening?

<!DOCTYPE html>
<html>
<head>
<style>
div {
  border: 3px solid #73AD21;
  height: 200px;
}
h1 {
margin-top: 50px;
  border: 3px solid #73AD21;
}
</style>
</head>
<body>


<div>
<h1>
sample
</h1>
</div>

</body>
</html>

0 Answers0