Any css masters know why this is happening? Or can explain it? The p is being hoisted to behave like it is inside the div by adding position relative to body. I know position:static
happens to the body by default, but when I set it to relative, the p tag behaves like it is nested inside the div tag. Anyone knows why this behavior is happening?
body {
background-color: purple;
margin: 0px;
padding: 0px;
position: relative;
}
div {
background-color: red;
height: 100px;
position: relative;
margin:0px;
padding: 0px;
}
p {
background-color: blue;
position: absolute;
bottom: 0px;
margin:0px;
}
<!DOCTYPE html>
<html>
<body>
<div>
<!-- it behaves like if it was here -->
</div>
<p>Hello World</p>
</body>
</html>