Hello, I can’t understand certain things about “position: absolute” in css. Most of the time, things work as I expect, but there must be a certain concept I don’t know about and it’s really making me frustrated. I’d really appreciate if somebody can pinpoint it for me.
Here is my example code. With “position: relative” boxes get positioned as expected. Now, the change is needed to make the greenish transparent box with Hello text above the picture. So, ‘absolute’ is needed. However, the next box ‘Blahblah’ (in blue) somehow inherits the absolute(?!) in a very weird way! What is needed in this code to make the ‘Blahblah’ box continue below the picture (as in relative).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
*,
html,
body {
padding: 0;
margin: 0;
}
.tops {
position: relative;
width: 350px;
height: 100px;
background-color: blue;
z-index: 200;
}
.onebelow {
width: 350px;
background-color: aqua;
}
.ouch {
position: absolute;
margin-top: 50px;
/*margin-top: 407px;*/
width: 254px;
height: 189px;
background: rgb(14, 72, 80);
background: rgba(14, 72, 80, 0.5);
color: white;
font-size: 42px;
padding-left: 163px;
padding-top: 29px;
line-height: 125px;
z-index: 10;
}
.top {
position: absolute;
z-index: 2;
width: 100%;
border: 2px solid red;
}
.selse,
.hrowx{
position: relative;
}
</style>
</head>
<body>
<header>
<div class="hrowx">
<div class="top">
<img id="my_image" src="https://img-s-msn-com.akamaized.net/tenant/amp/entityid/BBKHUZJ.img?h=416&w=799&m=6&q=60&u=t&o=f&l=f&x=1700&y=1854" />
</div>
<div class="ouch">
Hello!
<div class="nothing">
<p><sup>2</sup></p>
</div>
</div>
</div>
</header>
<section>
<div class="selse">
<div class="tops">
Blahblah
</div>
</div>
</section>
</body>
</html>