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

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

19.556 Lượt nghe
How to set max-columns using auto-fit or auto-fill
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](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!