When you set mycol
to have a position: absolute
, it removes it from the normal flow of the page. This can be demonstrated as follows:
<div class="mycol" style="position: absolute; height: 80%; width: 88%; background-color: rgba(255, 0, 0, .4); top: 150px; left: 240px;">
</div>
<div class="testclass" style="margin-left: 500px; height: 500px; width: 500px; background-color: black;"></div>
You will notice that the testclass
remains unaffected by the positioning of mycol
.
Therefore, in your scenario, even though the red box is visible, it does not impact the placement of "Hello World".
If the objective is to move the text below the red box without using the position technique, margins can be utilized. One option is to use percentages for margin-top, such as: margin-top: 80%
. However, this may result in unexpected outcomes as per W3 specifications which state that margin-top is based on the width of its container when using percentages.
Nevertheless, this approach does provide a solution to your query!
<div class="mycol" style="position: absolute; height: 80%; width: 88%; background-color: rgba(255, 0, 0, .4); top: 150px; left: 240px;">
</div>
<div class="testclass" style="margin-top:100%; background-color: gray;">
Hello world
</div>