freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/css-grid/reduce-repetition-using-the...

2.6 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
5a94fe3669fb03452672e45f Reduce Repetition Using the repeat Function 0 使用重复功能减少重复

Description

使用grid-template-columnsgrid-template-rows定义网格结构时为所创建的每个行或列输入了一个值。让我们说你想要一个100行相同高度的网格。单独插入100个值是不太实际的。幸运的是有一种更好的方法 - 使用repeat函数指定要重复列或行的次数后跟逗号和要重复的值。这是一个创建100行网格的示例每行高度为50px。
grid-template-rowsrepeat100,50px;
您还可以使用repeat函数重复多个值并在定义网格结构时将该函数插入其他值中。这就是我的意思
grid-template-columnsrepeat2,1fr 50px20px;
这意味着:
grid-template-columns1fr 50px 1fr 50px 20px;
注意
1fr 50px重复两次然后是20px。

Instructions

使用repeatgrid-template-columns属性中删除重复。

Tests

tests:
  - text: <code>container</code>类应具有<code>grid-template-columns</code>属性该属性设置为重复3列宽度为<code>1fr</code> 。
    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), "<code>container</code> class should have a <code>grid-template-columns</code> property that is set to repeat 3 columns with the width of <code>1fr</code>.");'

Challenge Seed

<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;
    /* change the code below this line */

    grid-template-columns: 1fr 1fr 1fr;

    /* change the code above this line */
    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>

Solution

// solution required