How to center align a div horizontally and vertically both.

HARSH VATS - Jul 22 '20 - - Dev Community

Let's say you have a code

<div id='parent'>
   <div id='child'>hello</div>
</div>
Enter fullscreen mode Exit fullscreen mode

and you want to make the child element to be centered horizontally and vertically both. How will you do that??
Actually it's pretty simple.

#parent {
    display: grid;
    place-items: center;
}
Enter fullscreen mode Exit fullscreen mode

and it's done. Bbye..

. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player