by Anonymous
How to center a div ?
Using flexbox to center a div :
div {
display: flex;
align-items: center;
justify-content: center;
}
Using grid to center a div :
div {
display: grid;
place-content: center;
}
Using Position to center a div :
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Using both grid and margin to center a div :
.parent {
display: grid;
}
.child {
margin: auto;
}
Using both flex and margin to center a div :
.parent {
display: flex;
}
.child {
margin: auto;
}