---
id: 5a94fe3669fb03452672e45f
title: Reduce Repetition Using the repeat Function
challengeType: 0
videoUrl: ''
localeTitle: 使用重复功能减少重复
---
## Description
使用grid-template-columns
和grid-template-rows
定义网格结构时,为所创建的每个行或列输入了一个值。让我们说你想要一个100行相同高度的网格。单独插入100个值是不太实际的。幸运的是,有一种更好的方法 - 使用repeat
函数指定要重复列或行的次数,后跟逗号和要重复的值。这是一个创建100行网格的示例,每行高度为50px。 grid-template-rows:repeat(100,50px);
您还可以使用repeat函数重复多个值,并在定义网格结构时将该函数插入其他值中。这就是我的意思: grid-template-columns:repeat(2,1fr 50px)20px;
这意味着: grid-template-columns:1fr 50px 1fr 50px 20px;
注意
1fr 50px
重复两次,然后是20px。
## Instructions
使用repeat
从grid-template-columns
属性中删除重复。
## Tests
```yml
tests:
- text: container
类应具有grid-template-columns
属性,该属性设置为重复3列,宽度为1fr
。
testString: 'assert(code.match(/.container\s*?{[\s\S]*grid-template-columns\s*?:\s*?repeat\s*?\(\s*?3\s*?,\s*?1fr\s*?\)\s*?;[\s\S]*}/gi), "container
class should have a grid-template-columns
property that is set to repeat 3 columns with the width of 1fr
.");'
```
## Challenge Seed
## Solution
```js
// solution required
```