MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/webdev/comments/1k7lxj5/css_grid_centered_positioning_does_not_work/
r/webdev • u/Prestigiouspite • Apr 25 '25
Hello, do you have any idea why element 5 is not centered correctly in the mobile view?
@media (max-width: 600px) { .grid-container-count-5 > :nth-child(5) { grid-column: 1 / span 2; /* spans both columns */ grid-row: 3; justify-self: center; } }
https://jsfiddle.net/7rju1akx/
4 comments sorted by
6
It is. But the grid container is bigger than you expect.
Use justify-items center instead of justify-content in the grid container.
2 u/Prestigiouspite Apr 25 '25 Many thanks for the tip! And no AI model could reveal it to me :D
2
Many thanks for the tip! And no AI model could reveal it to me :D
3
Use your browser debugger to visualise the grid. You can see the number 5 is centered: https://imgur.com/a/j5y9Y29
6
u/[deleted] Apr 25 '25
It is. But the grid container is bigger than you expect.
Use justify-items center instead of justify-content in the grid container.
3
u/ferrybig Apr 25 '25
Use your browser debugger to visualise the grid. You can see the number 5 is centered: https://imgur.com/a/j5y9Y29