Two right ways to center a div in CSS in 2023
Jan 10, 2023
When you google this question, you will find a lot of ways to do it. π
Butβ¦ It will be out of date. π
In 2023, we have only 2 right ways to do it:
1. Flex
.parent {
display: flex;
justify-content: center;
align-items: center;
}
2. Grid
.parent {
display: grid;
place-items: center;
}
Happy hacking! βπ»π