So I am not a web developer and have very little experience with html and css so this might sound dumb:
But I saw code from my co worker who set a section
to position:relative
and the child element (an h1
in this case) to position: absolute; top: 0; left: 0; height: 100%; width:100%
and somehow the h1
took the entire height and width of the parent which was the section
.
I tried reproducing it below but it was not possible. Seems like the h1 has a height of zero since the border is not surrounding it. Is there something wrong with the code below?
<!DOCTYPE html>
<html>
<head>
<style>
.main {
background-color: blue;
position: relative;
}
h1 {
position: absolute;
top: 0;
left: 0;
border: 1px solid black;
height: 100%;
width: 100%;
}
</style>
<title>Page Title</title>
</head>
<body>
<section class="main">
<h1>This is a Heading</h1>
</section>
</body>
</html>