I’m not able to set the height in percentage for absolute elements.
Why is this?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Absolute positioning testing</title>
<style>
.positionedParent {
border: 2px solid red;
background-color: aqua;
position: relative;
float: left;
height: 100%;
width: 100%;
}
.sopp {
width: 100%;
/* I can set in px, but not in % */
/* height: 10px; */
height:50%;
background-color: rgb(8, 184, 200);
position: absolute;
}
</style>
</head>
<body onload="alert(document.getElementById('a').offsetWidth);">
<div class="positionedParent">
<div class="sopp">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maxime laboriosam, iure dolor est,
eum temporibus numquam magnam atque sint, ipsam nisi provident quidem unde sapiente voluptas quas fugit
eveniet cumque natus doloribus amet soluta!</div>
</div>
<style>
#a {
position: absolute;
/* Without position absolute the width is, well, as expected, 100px. */
/* But with absolute positioning the width is 736px
When an element has position:absolute, the width and height percentages are calculated based on the whole browser dimensions. */
/* So u gotta set % units based on the whole body or use a different unit altogether. */
width: 50%;
}
</style>
<div style="width:200px;">
<div id="a">Hello</div>
</div>
<div style="width:200px; position:relative">
<div id="b">HEYLO</div>
</div>
</body>
</html>