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

后端 未结 9 1288
走了就别回头了
走了就别回头了 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条回答
  •  星月不相逢
    2020-12-22 22:03

    Here's some reusable css that will preserve the height of each element without using position: absolute:

    .stack {
        display: grid;
    }
    .stack > * {
        grid-row: 1;
        grid-column: 1;
    }
    

    The first element in your stack is the background, and the second is the foreground.

提交回复
热议问题