How to overlay one div over another div

前端 未结 9 2043
旧时难觅i
旧时难觅i 2020-11-21 17:39

I need assistance with overlaying one individual div over another individual div.

My code looks like this:

9条回答
  •  佛祖请我去吃肉
    2020-11-21 18:03

    The new Grid CSS specification provides a far more elegant solution. Using position: absolute may lead to overlaps or scaling issues while Grid will save you from dirty CSS hacks.

    Most minimal Grid Overlay example:

    HTML

    This is the content
    Overlay - must be placed under content in the HTML

    CSS

    .container {
      display: grid;
    }
    
    .content, .overlay {
      grid-area: 1 / 1;
    }
    

    That's it. If you don't build for Internet Explorer, your code will most probably work.

提交回复
热议问题