
css grid 布局中的难题
问题 1:
当使用 grid-template-columns: repeat(auto-fill, 20%); 时,如何让 .box1 中的元素在 1 行中显示 5 个?
问题 2:
当使用 grid-template-columns: auto auto auto auto auto; 时,如何在 .box2 中元素不足的情况下保持它们的宽度不变?
立即学习“前端免费学习笔记(深入)”;
解决方案:
问题 1:
可以修改 grid-template-columns 属性:
grid-template-columns: repeat(auto-fit, calc((100% - 4 * 20px) / 5));
问题 2:
可以使用 minmax() 函数设置元素的最小和最大宽度:
grid-template-columns: repeat(auto-fill, minmax(0px, auto));
以上就是CSS Grid 布局疑难解答:如何实现特定行数元素显示和保持元素宽度不变?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号