freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/css-grid/create-flexible-layouts-using-auto-fit.md

1.2 KiB

id, title, challengeType, videoUrl, forumTopicId
id title challengeType videoUrl forumTopicId
5a94fe6269fb03452672e462 使用 auto-fit 创建弹性布局 0 https://scrimba.com/p/pByETK/c3dPph8 301127

--description--

auto-fit效果几乎和auto-fill一样。不同点仅在于,当容器的大小大于各网格项之和时,auto-fill将会持续地在一端放入空行或空列,这样就会使所有网格项挤到另一边;而auto-fit则不会在一端放入空行或空列,而是会将所有网格项拉伸至合适的大小。

注意:
如果容器无法使所有网格项放在同一行,余下的网格项将移至新的一行。

--instructions--

在第二个网格中,用auto-fitrepeat来填充网格,其中列宽的最小值为60px,最大值为1fr。你可以调整最右侧的预览区以查看差异。

--hints--

container2类应该有grid-template-columns属性,且使用repeatauto-fit以便将最小宽度为60px,最大宽度为1fr的列放入网格。

assert(
  code.match(
    /.container2\s*?{[\s\S]*grid-template-columns\s*?:\s*?repeat\s*?\(\s*?auto-fit\s*?,\s*?minmax\s*?\(\s*?60px\s*?,\s*?1fr\s*?\)\s*?\)\s*?;[\s\S]*}/gi
  )
);

--solutions--