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

后端 未结 9 1242
走了就别回头了
走了就别回头了 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:04

    Here's another solution using display: flex instead of position: absolute or display: grid.

    .container_row{
      display: flex;
    }
    
    .layer1 {
      width: 100%;
      background-color: rgba(255,0,0,0.5);  // red
    }
    
    .layer2{
      width: 100%;
      margin-left: -100%;
      background-color: rgba(0,0,255,0.5);  // blue
    }
    Lorem ipsum...
    More lorem ipsum...
    ...same HTML as above. This one should never overlap the .container_row above.

提交回复
热议问题