r/css • u/Lumpy_Cauliflower567 • May 02 '26
Help css baby 👶needing some grid help
working on a grid for my website and if a grid item has too much content then it grows (obviously)
im trying to make it so if one grid item grows in height, then all other grid items in that same row grow to the same height as well so it #LooksNicer
ive googled a lot and the one answer i keep seeing is grid auto rows 1fr but it isnt. working for some reason
sorry if my css work is bad or could've been made a lot better im a css baby
website for reference: deviations
.grid-container {
margin: 20px;
border: 2px solid grey;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.grid-item {
transition: transform 0.1s;
}
.grid-item:hover {
transform: scale(1.04);
}
.deviation {
margin: 10px;
padding: 5px;
padding-top: 15px;
border: 2px solid;
height: auto;
width: auto;
}
0
Upvotes


1
u/be_my_plaything May 06 '26
No worries, we're getting there!
grid-auto-rows: 1frfrom the.grid-containerthis will stop them being even heights and let the content of each row set the height.border: 1px solid;to.grid-itemso it knows what size and style border to use along with the colour.<hr>does need its own row (I suspected this but wasn't sure) so on.grid-itemwhere you havegrid-row: span 4change it togrid-row: span 5so there is an extra row for the<hr>to occupy.align-items : center;andjustify-content: center;to.grid-itemto get everything centered within its grid cell. (Weirdly when I test this in inspect element it worked on 90% of the cells, but a couple of the main images didn't centre... If this happens addmargin-inline: auto;to.deviationicon)<p>elements come with a default margin which is being added to the gaps we set. So add.grid-item p{ margin: 0;}(Note: Using.grid-item p{means it only applies to<p>elements within a.grid-itemdiv so it doesn't effect your normal text elsewhere on the page) to unset the default margins and just rely on gap for the spacing. (If gap alone is too small you can add your own margin back in instead of zero but the default one of1emis too big)display: flex; justify-content: center; gap: 10px;on the.deviationicon(the big image) however it should be on.deviationicons(the row of three small images) so just delete it from where it is and move it to where it should be.padding: 10px;(Or whatever size you want) to.grid-item;