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

2.0 KiB
Raw Blame History

id title challengeType videoUrl forumTopicId dashedName
587d78ae367417b2b2512afd 使用 flex-basis 属性设置元素的初始大小 0 https://scrimba.com/p/pVaDAv/c3d9nCa 301108 use-the-flex-basis-property-to-set-the-initial-size-of-an-item

--description--

flex-basis 属性定义了在使用 CSS 的 flex-shrinkflex-grow 属性对元素进行调整前,元素的初始大小。

flex-basis 属性的单位与其他表示尺寸的属性的单位一致(pxem% 等)。 如果值为 auto,则项目的尺寸随内容调整。

--instructions--

使用 flex-basis 为盒子设置初始值。 请给 #box-1#box-2 添加 CSS 属性 flex-basis。 设置 #box-1 的尺寸初始值为 10em#box-2 的尺寸初始值为 20em

--hints--

#box-1 元素应具有 flex-basis 属性。

assert($('#box-1').css('flex-basis') != 'auto');

#box-1flex-basis 属性值应为 10em

assert(code.match(/#box-1\s*?{\s*?.*?\s*?.*?\s*?flex-basis:\s*?10em;/g));

#box-2 元素应具有 flex-basis 属性。

assert($('#box-2').css('flex-basis') != 'auto');

#box-2flex-basis 属性值应为 20em

assert(code.match(/#box-2\s*?{\s*?.*?\s*?.*?\s*?flex-basis:\s*?20em;/g));

--seed--

--seed-contents--

<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>

--solutions--

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

  #box-1 {
    background-color: dodgerblue;
    height: 200px;
    flex-basis: 10em;
  }

  #box-2 {
    background-color: orangered;
    height: 200px;
    flex-basis: 20em;
  }
</style>

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