Using CSS Grid and Flexbox, we can center a .div using margin:auto in our flex item. Using the position property requires a few more lines of code, but don't worry! It's still an easy way. We first need to set the position of our parent element to relative, followed by our child element position to absolute.

•2m read time•From yuricodesbot.hashnode.dev
Post cover image
Table of contents
Using CSS GridUsing FlexboxUsing MarginUsing the position property
2 Comments

Sort: