Categories
Uncategorized

3 Ways to Center a Div

Somehow I always seems to struggle to center block elements so I write a small note (mostly for myself) how to do it.

1. Old School margin:auto

div{
margin-left: auto;
margin-right: auto;
}

2. Flex and the justify-content

div{
display:flex;
height:100vh;
align-items:center:
justify-content:center;

}

3. Grid and setting the place-items

div{
display:grid;
height:100vh;
place-items: center;
}