0:00
Centering a div in CSS can seem tricky,
0:02
but with the right methods, it is
0:04
simple. Here are the top three ways to
0:07
center a div. Perfect for beginners.
0:12
Set the parent container display to
0:14
flex. Then add justify content center
0:17
and align item center. Your div will be
0:20
perfectly centered both vertically and
0:24
Next, CSS grid. Make the parent display
0:27
grid. Then use place item center. This
0:30
centers your div in both directions with
0:32
just two lines of code.
0:34
Finally, the classic margin auto. Set a
0:37
fixed width for your div. Then add
0:40
margin left and right auto. It centers
0:42
the div horizontally. Like and subscribe