H
H
hannyto11112021-06-22 13:45:16
css
hannyto1111, 2021-06-22 13:45:16

Why is position: absolute not set to 0:0 by default?

Hello, after executing this code, the yellow square will become lower than the green one and not at the 0,0 position, why is this happening - shouldn't it be at 0:0 by default?

<div class="mydiv">
</div>
<div class="divy">
</div>
<style>

.mydiv{
height: 5vmin;
width: 5vmin;
background: green;
}
.divy{
height: 5vmin;
width: 5vmin;
background: yellow;
position: absolute;
}
</style>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Volkov, 2021-06-22
@hannyto1111

If you define position: absolute on box-4, that element will leave the normal flow of the document. But it remains in its place, since the offset coordinates are not set

https://proglib.io/p/css-position-absolute/
If you make a third div it will go under the second one which has position:absolute. Since he left the main stream
60d1c539e222b055080445.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question