DEV Community

HARSH VATS
HARSH VATS

Posted on

4

How to center align a div horizontally and vertically both.

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..

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video