[Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def

 

 

What about the situation in which we aren’t specifying the number of columns or rows to be repeated? There are two properties we can use in this situation; auto-filland auto-fit. We’ll explore what each one does and why we would need to use them on our grid-tracks.

 

For example, we have current solution:

            grid-template-columns:
                    repeat(
                            3, /*each row has 3 repeat items*/
                            minmax(10px, auto)
                            minmax(20px, auto)
                            minmax(40px, auto)
                            minmax(80px, auto)
                    );

We tell it to repeat 3 times for a row.

But what if we don't want to hardcoded '3'. We want to dynamic change according to viewport.

 

We can use 'auto-fill' for that:

            grid-template-columns:
                    repeat(
                            auto-fill, /*each row has 3 repeat items*/
                            minmax(50px, auto)
                            minmax(70px, auto)
                            minmax(90px, auto)
                            minmax(110px, auto)
                    );

 

 

 

We if we don't have enough box to fill the whole space. We can use 'auto-fit':

 

            grid-template-columns:
                    repeat(
                            auto-fit,
                            minmax(50px, auto)
                            minmax(70px, auto)
                            minmax(90px, auto)
                    );

 

 

posted @   Zhentiw  阅读(320)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2016-03-28 [Angular 2] @Input Custom public property naming
2016-03-28 [React] React Router: IndexRoute
2016-03-28 [React] React Router: Nested Routes
2016-03-28 [React] React Router: hashHistory vs browserHistory
2016-03-28 [React] React Router: activeStyle & activeClassName
2016-03-28 [React] React Router: Router, Route, and Link
2015-03-28 [Whole Web] [AngularJS] Localize your AngularJS Application with angular-localization
点击右上角即可分享
微信分享提示