I have a parent named "container" of size 300px x 120px that encapsulates 2 s namely "redbox" and "greenbox". when I add "position: relative" to the "container" size of child <div>
s looks proportionate. however on removing the attribute size of div increases 3 times".
to my knowledge position is for positioning of elements how can it effect the size of the element.
#container {
width: 300px;
height: 120px;
/*position: relative;*/
border: solid 1px blue;
}
#redbox,
#greenbox {
border: solid 1px;
width: 60%;
height: 60%;
position: absolute;
}
#redbox {
background-color: red;
left: 0px;
top: 0px;
}
#greenbox {
background-color: rgb(21, 255, 0);
left: 30px;
top: 30px;
opacity: 50%;
}
<head></head>
<body>
<div id="container">
<div id="redbox"></div>
<div id="greenbox"></div>
</div>
</body>