I set the body
position to relative
, then I'm trying to position #first
and #second
elements relative to their parents, i.e. the body
.
My question is why the #first
element is not inside of the body
when their positions are absolute/fixed?
body {
margin: 0;
padding: 0;
border: solid red;
position: relative;
}
#first {
position: fixed;
left: 0;
top: 200px;
border: solid green;
}
#second {
border: solid blue;
height: 200px;
padding: 100px;
position: absolute;
}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<section id="first"></section>
<section id="second"> </section>
</body>
</html>