E
E
Eugenue Cesarevich2021-06-21 13:23:34
css
Eugenue Cesarevich, 2021-06-21 13:23:34

How to make a div on top of content?

There is a structure:

<div id='parent'>
    <div id='child'>
    <div/>
<div/>

I want the child div not to shift the rest of the elements in the parent div, but rather to be on top of them. This effect can be achieved if you use position: absolute, but that's bad luck, positioning still needs to be relative to the div parent, and if you use position: absolute, then positioning is absolute, not relative.

How do I get the "on top of content" effect that gives position: absolute, but the positioning is relative?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TRNER, 2021-06-21
@cot_shaurma

Add position: relative div with parent id

A
asmodeus13th, 2021-06-21
@asmodeus13th

Eugenue Cesarevich , the point is that "position: absolute" works from the nearest parent element with "position: relative". By default, "position: absolute" is pushed off the document.

<div id="parent">
  <div id="child">
  </div>
</div>

Add "position: relative" to the element you want to bounce from. When changing the position via top/bottom/left/right , the coordinates will start from the relative positioned element.
#child{
  position: absolute;
}
#parent{
  position: relative;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question