r/WebdevTutorials • u/webdep • Mar 01 '21
Frontend 5 Simple ways to center a div using CSS
https://www.codingflicks.com/2021/02/5-ways-to-center-div-using-css.html
35
Upvotes
5
u/icewaterJS Mar 01 '21
Idk if you made this but the very first method (Flexbox) shows the code snippet from the second method (Tables).
Assuming empty divs it should be...
.parent {
width: 400px;
height: 400px;
background: black;
display: flex;
justify-content: center;
align-items: center;
}
.child {
width: 100px;
height: 100px;
background: deepskyblue;
}2
6
u/og-at Mar 01 '21
The CSS grid version can be way simpler. On the parent
and no requirements on the child.
On css-tricks.