freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/css-grid/limit-item-size-using-the-m...

2.5 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
5a94fe4469fb03452672e460 Limit Item Size Using the minmax Function 0 限制项目大小使用minmax功能

Description

还有另一个内置函数可用于grid-template-columnsgrid-template-rows称为minmax 。当网格容器改变大小时,它用于限制项目的大小。为此,您需要指定项目的可接受尺寸范围。这是一个例子:
grid-template-columns100px minmax50px200px;
在上面的代码中, grid-template-columns设置为创建两列;第一个是100px宽第二个是最小宽度50px最大宽度是200px。

Instructions

使用minmax函数,将repeat函数中的1fr替换为最小宽度为90px且最大宽度为1fr的列大小,并调整预览面板的大小以查看效果。

Tests

tests:
  - text: <code>container</code>类应具有<code>grid-template-columns</code>属性该属性设置为重复3列最小宽度为<code>90px</code> ,最大宽度为<code>1fr</code> 。
    testString: 'assert(code.match(/.container\s*?{[\s\S]*grid-template-columns\s*?:\s*?repeat\s*?\(\s*?3\s*?,\s*?minmax\s*?\(\s*?90px\s*?,\s*?1fr\s*?\)\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 minimum width of <code>90px</code> and maximum 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: repeat(3, 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