CSS: How to position two elements on top of each other, without specifying a height?

后端 未结 9 1280
走了就别回头了
走了就别回头了 2020-12-22 21:37

I have two DIVs that I need to position exactly on top of each other. However, when I do that, the formatting gets all screwed up because the containing DIV acts like there

9条回答
  •  梦毁少年i
    2020-12-22 22:07

    Great answer, "mu is too short". I was seeking the exact same thing, and after reading your post I found a solution that fitted my problem.

    I was having two elements of the exact same size and wanted to stack them. As each have same size, what I could do was to make

    position: absolute;
    top: 0px;
    left: 0px;
    

    on only the last element. This way the first element is inserted correctly, "pushing" the parents height, and the second element is placed on top.

    Hopes this helps other people trying to stacking 2+ elements with same (unknown) height.

提交回复
热议问题