# CSS 網格 - 使用 minmax 函數限制項目大小

**URL:** <https://forum.freecodecamp.org/t/css-minmax/545798>\
**Category:** General\
**Created:** [August 22, 2022, 7:14am UTC](https://forum.freecodecamp.org/t/css-minmax/545798 "2022-08-22T07:14:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Music\_Meow](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/music_meow/32/279696_2.png) [@Music\_Meow](https://forum.freecodecamp.org/u/Music_Meow)\
**Post date:** [August 22, 2022, 7:14am UTC](https://forum.freecodecamp.org/t/css-minmax/545798/1 "2022-08-22T07:14:31Z")

</div>

**告訴我們發生了什麼：**  
在此詳細描述你的問題。

```
  **你目前的代碼**

```

```html
<style>
.item1{background:LightSkyBlue;}
.item2{background:LightSalmon;}
.item3{background:PaleTurquoise;}
.item4{background:LightPink;}
.item5{background:PaleGreen;}

.container {
  font-size: 40px;
  min-height: 300px;
  width: 100%;
  background: LightGray;
  display: grid;
  /* 只修改這一行下面的代碼 */

  grid-template-columns: repeat(3 minmax (90px, 1fr));

  /* 只修改這一行上面的代碼 */
  grid-template-rows: 1fr 1fr 1fr;
  grid-gap: 10px;
}
</style>

<div class="container">
<div class="item1">1</div>
<div class="item2">2</div>
<div class="item3">3</div>
<div class="item4">4</div>
<div class="item5">5</div>
</div>

```

```
  **你的瀏覽器信息：**

```

用戶代理是： `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36`

**挑戰：** CSS 網格 - 使用 minmax 函數限制項目大小

**挑戰的鏈接：**

> **[freeCodeCamp.org](https://www.freecodecamp.org/chinese-traditional/learn/responsive-web-design/css-grid/limit-item-size-using-the-minmax-function)**
>
> 免費學習編程

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [August 22, 2022, 9:39am UTC](https://forum.freecodecamp.org/t/css-minmax/545798/2 "2022-08-22T09:39:07Z")

</div>

> [@Music\_Meow](#):
>
> `repeat(3 minmax (90px, 1fr)`

missing comma `,` between the arguments after the `3`

---

<div class="post-metadata">

**Author:** ![Odelia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/odelia/32/284156_2.png) [@Odelia](https://forum.freecodecamp.org/u/Odelia)\
**Post date:** [September 21, 2022, 1:49pm UTC](https://forum.freecodecamp.org/t/css-minmax/545798/3 "2022-09-21T13:49:31Z")

</div>

repeat(3, 90px 1fr);  
参考

> **[repeat() - CSS（层叠样式表） | MDN](https://developer.mozilla.org/zh-CN/docs/Web/CSS/repeat)**
>
> CSS repeat() 函数表示轨道列表的重复片段，允许以更紧凑的形式写入大量显示重复模式的列或行。

```auto
grid-template-columns: repeat(2, 50px 1fr) 100px;

```

 ![grid-template-columns](https://global.discourse-cdn.com/freecodecamp/original/4X/a/7/a/a7ad2d02381bd7e199752542e114a0f1ac1e0c6b.png)  
这行代码可以实现在一行中，创建50px,1fr,50px,1fr,100px共5个格子

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 7, 2025, 3:48pm UTC](https://forum.freecodecamp.org/t/css-minmax/545798/4 "2025-01-07T15:48:51Z")

</div>

Closed on January 7, 2025, 3:48pm UTC


