kevinpowell

How to set max-columns using auto-fit or auto-fill


Listen Later

It takes a little bit of work, but we can relatively easily take control of CSS Grid’s auto-fit (or auto-fill) by using a calc() to help set an upper limit on how many columns it creates.

πŸ”— Links

βœ… The code from this video: https://codepen.io/kevinpowell/pen/GgRwqxJ
βœ… The second version using attr(): https://codepen.io/kevinpowell/pen/ZYEBEre
βœ… auto-fit and auto-fill explained: https://www.youtube.com/watch?v=bj0Z_GncIwY
βœ… I’ve got free and premium courses: https://kevinpowell.co/courses

⌚ Timestamps

00:00 - Introduction
00:50 - Basic setup with auto-fit
03:00 - Having to do some math to make it work
05:28 - Making it more readable
06:30 - Making it stack at smaller sizes
09:10 - Preventing overflow
12:54 - An improvement we can make with a new CSS feature

#css

βœ‰ Keep up to date with everything I'm up to https://www.kevinpowell.co/newsletter

πŸ’¬ Come hang out with other devs in my Discord Community https://discord.gg/nTYCvrK
⭐ Are you a beginner? HTML & CSS for absolute beginners is for you: https://learn.kevinpowell.co
πŸŽ“ Start writing CSS with confidence with CSS Demystified: https://cssdemystified.com
πŸš€ Already mastered CSS? Check out my advanced course, Beyond CSS: https://www.beyondcss.dev/

Help support my channel

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

πŸ§‘β€πŸ’» My editor: VS Code - https://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: https://codepen.io/kevinpowell/
Github: https://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!

...more
View all episodesView all episodes
Download on the App Store

kevinpowellBy