DEV Community

Cover image for Div in Center using only 2 lines of  CSS code |  part-2

Div in Center using only 2 lines of CSS code | part-2

Shubham Jadhav on September 09, 2021

Hello, Coders... Today, I am showing you how to put an empty div in center in just Two lines of css code. So, let's begin our second part of ...
Collapse
 
masoud94 profile image
Masoud-94

Not really, just add this to your parent class:
display: grid;
place-items: center;

Collapse
 
afif profile image
Temani Afif

1 line or 10 lines is not the important part here. I don't really understand people thinking that writing less CSS code means a better CSS code. The most important is to add the correct CSS code. It's better to focus on the technique rather than the number of lines. centering is important here not centering with 2 lines of code