Design comparison
Solution retrospective
how do you center the grid in the middle of the page?
Community feedback
- @realsalePosted over 2 years ago
Yo! Lee,
In these case, I think what you really need is how to center grid items(rows/cols) and not the grid itself.
In order for you to align grid items, you must define your grid(container) dimension first, by setting it's
width
andheight
.If you haven't set the grid's height for example, then the grid is as tall as the grid items, therefore you can't visually see it's vertical alignment.
- You can center grid items by specifying
justify-content
andalign-content
property tocenter
. - There is also a shorthand property
place-content
that sets bothjustify-content
andalign-content
<div class="grid"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> </div>
.grid { display: grid; grid-template-columns: 250px 250px 250px; /* 3 columns with 250px width */ grid-template-rows: 600px; /* 1 row with 600px height */ height: 100vh; /* 100 viewport height */ place-content: center; /* shorthand for justify-content & align-content property */ }
Marked as helpful0@lee-fentressPosted over 2 years ago@realsale how do you adjust the border radius after you do that?
0@realsalePosted over 2 years agoYo! @lee-fentress,
In this very case, in order for you to set the child's
border-radius
is thruattribute selectors
to select/target the first and last child of an element, you can use
.grid-container div:first-child
then setborder-top-left-radius
andborder-top-right-radius
property of the first childand in the last-child you can use
.grid-container div:last-child
then set the respective styles.You can also use
attribute selectors
of this approach[class|="grid-item"]:first-child
and[class|="grid-item"]:last-child
Marked as helpful0@realsalePosted over 2 years agoThe easiest approach is to set
border-radius
andoverflow: hidden
to wrapper element.0 - You can center grid items by specifying
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord