9
useVim
2y

one of my friend is new to frontend dev.

and he's trying to center a div (text).

using position absolute and relative.

It's not working BTW.

We're communicating over text.
Must be loosing his mind.
He'll finally understand center div memes.

Comments
  • 4
    why not use flex?
  • 7
    .container {
    display: flex;
    justify-content: center;
    align-items: center;
    }
  • 0
    @TeachMeCode its an overlayed text over image
  • 0
    @useVim

    maybe (untested)...

    .container {

    position:fixed;

    top:0;

    left:0;

    right:0;

    bottom:0;

    display: flex;

    justify-content: center;

    align-items: center;

    }
  • 2
    margin: 0 auto;
  • 0
    Make a container with "position: relative". Place image and overlay in it.
    Let overlay have "position: absolute" and 0 on sides (left+right+top+bottom).
    Also let it have "display: grid" and "place-items: center".
Add Comment