freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/css-flexbox/use-the-flex-grow-property-...

1.9 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d78ae367417b2b2512afc Use the flex-grow Property to Expand Items 0 使用flex-grow属性扩展项目

Description

flex-shrink相反的是flex-grow属性。回想一下,当容器缩小时, flex-shrink控制项目的大小。当父容器展开时, flex-grow属性控制项的大小。使用上一个挑战中的类似示例,如果一个项目的flex-grow值为1而另一个项目的flex-grow值为3则值为3的项目将增长为另一个项目的三倍。

Instructions

将CSS属性flex-grow添加到#box-1#box-2 。将#box-1的值设为1#box-2的值设为2。

Tests

tests:
  - text: '<code>#box-1</code>元素应将<code>flex-grow</code>属性设置为值1。'
    testString: 'assert($("#box-1").css("flex-grow") == "1", "The <code>#box-1</code> element should have the <code>flex-grow</code> property set to a value of 1.");'
  - text: '<code>#box-2</code>元素应将<code>flex-grow</code>属性设置为值2。'
    testString: 'assert($("#box-2").css("flex-grow") == "2", "The <code>#box-2</code> element should have the <code>flex-grow</code> property set to a value of 2.");'

Challenge Seed

<style>
  #box-container {
    display: flex;
    height: 500px;
  }

  #box-1 {
    background-color: dodgerblue;
    height: 200px;

  }

  #box-2 {
    background-color: orangered;
    height: 200px;

  }
</style>

<div id="box-container">
  <div id="box-1"></div>
  <div id="box-2"></div>
</div>

Solution

// solution required