+ 2

Why is my CSS Grid not aligning items in the center?

I'm trying to center some content inside a grid, but it keeps getting stuck in the top-left corner. Here's the code I'm using: HTML CODE : <div class="grid"> <div class="item">Content</div> </div> CSS CODE: .grid { display: grid; height: 100vh; grid-template-columns: 1fr; grid-template-rows: 1fr; } .item { background: #333; color: white; } I'm not sure what I'm missing to make the content center both vertically and horizontally. Any ideas?

15th Sep 2024, 7:29 AM
Muhammad Nouman Ali
Muhammad Nouman Ali - avatar
3 Réponses
+ 2
add this to your .grid place-items:center;
15th Sep 2024, 8:07 AM
Bob_Li
Bob_Li - avatar
+ 1
Hii
17th Sep 2024, 7:15 AM
Gaurav Bansal
Gaurav Bansal - avatar
+ 1
17th Sep 2024, 9:18 AM
Muhammad Nouman Ali
Muhammad Nouman Ali - avatar