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

2.7 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d78ae367417b2b2512afe Use the flex Shorthand Property 0 使用flex速记属性

Description

有一个快捷方式可以同时设置多个flex属性。通过使用flex属性,可以将flex-grow flex-shrinkflex-basis属性设置在一起。例如, flex: 1 0 10px;将项目设置为flex-grow: 1; flex-shrink: 0; ,和flex-basis: 10px; 。默认属性设置为flex: 0 1 auto;

Instructions

将CSS属性flex添加到#box-1#box-2 。给#box-1赋值,使flex-grow为2 flex-shrink为2 flex-basis为150px。给#box-2赋值,使flex-grow为1 flex-shrink为1flex-basis为150px。这些值将导致#box-1增长以在容器大于300px时以#box-2两倍速率填充额外空间并在容器小于300px时以#box-2的速率缩小两倍。 300px是两个框的flex-basis值的组合大小。

Tests

tests:
  - text: '<code>#box-1</code>元素的<code>flex</code>属性应设置为2 2 150px。'
    testString: 'assert($("#box-1").css("flex-grow") == "2" && $("#box-1").css("flex-shrink") == "2" && $("#box-1").css("flex-basis") == "150px", "The <code>#box-1</code> element should have the <code>flex</code> property set to a value of 2 2 150px.");'
  - text: '<code>#box-2</code>元素的<code>flex</code>属性应设置为1 1 150px。'
    testString: 'assert($("#box-2").css("flex-grow") == "1" && $("#box-2").css("flex-shrink") == "1" && $("#box-2").css("flex-basis") == "150px", "The <code>#box-2</code> element should have the <code>flex</code> property set to a value of 1 1 150px.");'
  - text: '您的代码应该使用<code>#box-1</code>和<code>#box-2</code>的<code>flex</code>属性。'
    testString: 'assert(code.match(/flex:\s*?\d\s+?\d\s+?150px;/g).length == 2, "Your code should use the <code>flex</code> property for <code>#box-1</code> and <code>#box-2</code>.");'

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