A CSS Trick to select a specific row with Grid auto-fit/fill @KevinPowell
A CSS Trick to select a specific row with Grid auto-fit/fill  @KevinPowell
Uploaded August 2025 | Updated September 2026, 2 weeks ago
Looking to step up your CSS Game? Check out cssdemystified.com

πŸ”— Links
βœ… Code for last row only: codepen.io/kevinpowell/pen/ogjwxyv/19639a71b6ff26e1bf87738fa6db12d5
βœ… Code for first two rows only: codepen.io/kevinpowell/pen/vENZGvG/14a4bdacb2fa79bbdd9cd1e400b57097
βœ… Code for 2nd row only: codepen.io/kevinpowell/pen/YPyQqMq/990300b888e8aec0d77d520d5948ddb5
βœ… Keith’s article: keithclark.co.uk/articles/targeting-first-and-last-rows-in-css-grid-layouts
βœ… Temani’s version with no container queries: codepen.io/t_afif/pen/QwbZKPB?editors=1100

βœ‰ Keep up to date with everything I'm up to kevinpowell.co/newsletter
πŸ’¬ Come hang out with other devs in my Discord Community discord.gg/nTYCvrK
⭐ Are you a beginner? HTML & CSS for absolute beginners is for you: learn.kevinpowell.co
πŸŽ“ Start writing CSS with confidence with CSS Demystified: [https://cssdemystified.com](https://cssdemystified.com/)
πŸš€ Already mastered CSS? Check out my advanced course, Beyond CSS: https://www.beyondcss.dev/

⌚ Timestamps
00:00 - Introduction
00:45 - Requirements for this to work
01:45 - Setting up the first container query
03:00 - Getting the first two rows
05:10 - Getting only the second row
07:00 - Selecting the last row
13:44 - Using new CSS features so we don’t need container queries

#css


---

Help support my channel
πŸ‘¨β€πŸŽ“ Get a course: kevinpowell.co/courses
πŸ‘• Buy a shirt: cottonbureau.com/people/kevin-powell
πŸ’– Support me on Patreon: patreon.com/kevinpowell or through YT memberships: youtube.com/@KevinPowell/join

---

πŸ§‘β€πŸ’» My editor: VS Code - code.visualstudio.com

🌈 My theme: One Dark Pro Var Night
πŸ”€ My font: Cascadia Code

---

I'm on some other places on the internet too!

If you'd like a behind the scenes and previews of what's coming up on my YouTube channel:

Bluesky: https://bsky.app/profile/kevinpowell.co
Codepen: codepen.io/kevinpowell
Github: github.com/kevin-powell

---

And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!
A CSS Trick to select a specific row with Grid auto-fit/fillFigma Sites is worse than you might have thoughtLooks good, but kinda broken. Right on brand for Ferarri.CSS one-liner to improve form elementsCSS lessons for your parking failsRedesigning a webpageWhen tech interview tests are brokenScroll-driven animations without any JSCreate a reusable Web Component from scratchBreakpoint-Free CSS Grid LayoutsDirectionally aware button effect without JavaScript5 CSS tips every developer should know
Kevin Powell |

A CSS Trick to select a specific row with Grid auto-fit/fill

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER