--- id: 5a94fe6269fb03452672e462 title: 使用 auto-fit 創建彈性佈局 challengeType: 0 videoUrl: 'https://scrimba.com/p/pByETK/c3dPph8' forumTopicId: 301127 dashedName: create-flexible-layouts-using-auto-fit --- # --description-- `auto-fit` 效果幾乎和 `auto-fill` 一樣。 不同點僅在於,當容器的大小大於各網格項之和時,`auto-fill` 會持續地在一端放入空行或空列,這樣就會使所有網格項擠到另一邊;而 `auto-fit` 則不會在一端放入空行或空列,而是會將所有網格項拉伸至合適的大小。 **注意:** 如果容器寬度不足以將所有網格項放在同一行,餘下的網格項將會移至新的一行。 # --instructions-- 在第二個網格中,請用 `auto-fit` 和 `repeat` 來填充網格,其中列寬的最小值爲 `60px`,最大值爲`1fr`。 你可以調整最右側的預覽區來查看效果。 # --hints-- `container2` class 應該有一個 `grid-template-columns` 屬性,通過 `repeat` 和 `auto-fit` 將網格中的列的寬度設置爲最小 `60px`,最大 `1fr`。 ```js 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 ) ); ``` # --seed-- ## --seed-contents-- ```html
1
2
3
4
5
1
2
3
4
5
``` # --solutions-- ```html ```