CSS Grid 布局的行列问题
问题 1:box1:如何在一行中排列 5 个等宽项目?
在 grid-template-columns: repeat(auto-fill, 20%) 布局中,如果项目的尺寸超出容器的尺寸,它们将换行显示。要在一行中排列 5 个项目,可以使用 repeat(auto-fit, calc((100% - 4 * 20px) / 5)),其中:
问题 2:box2:当项目数量不足时,如何保持项目宽度不变?
在 grid-template-columns: auto auto auto auto auto 布局中,如果项目数量不足,容器中将出现多余空间。为了防止这种情况,可以使用 auto-fill-measure 属性,将项目宽度限制为容器的可用空间:
grid-template-columns: auto auto auto auto auto auto-fill-measure;