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

2.4 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d78ae367417b2b2512afd Use the flex-basis Property to Set the Initial Size of an Item 0 使用flex-basis属性设置项的初始大小

Description

flex-basis属性指定CSS在使用flex-shrinkflex-grow进行调整之前的项的初始大小。 flex-basis属性使用的单位与其他大小属性( px em %等)相同。该值根据内容auto项目大小。

Instructions

使用flex-basis设置框的初始大小。将CSS属性flex-basis添加到#box-1#box-2 。给#box-1一个值为10em #box-2给一个值为20em

Tests

tests:
  - text: '<code>#box-1</code>元素应该具有<code>flex-basis</code>属性。'
    testString: 'assert($("#box-1").css("flex-basis") != "auto", "The <code>#box-1</code> element should have a <code>flex-basis</code> property.");'
  - text: '<code>#box-1</code>元素的<code>flex-basis</code>值应为<code>10em</code> 。'
    testString: 'assert(code.match(/#box-1\s*?{\s*?.*?\s*?.*?\s*?flex-basis:\s*?10em;/g), "The <code>#box-1</code> element should have a <code>flex-basis</code> value of <code>10em</code>.");'
  - text: '<code>#box-2</code>元素应该具有<code>flex-basis</code>属性。'
    testString: 'assert($("#box-2").css("flex-basis") != "auto", "The <code>#box-2</code> element should have the <code>flex-basis</code> property.");'
  - text: '<code>#box-2</code>元素的<code>flex-basis</code>值应为<code>20em</code> 。'
    testString: 'assert(code.match(/#box-2\s*?{\s*?.*?\s*?.*?\s*?flex-basis:\s*?20em;/g), "The <code>#box-2</code> element should have a <code>flex-basis</code> value of <code>20em</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