3.0 KiB
3.0 KiB
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
587d78ad367417b2b2512afa | 使用 flex-wrap 屬性包裹一行或一列 | 0 | https://scrimba.com/p/pVaDAv/cQv9ZtG | 301114 | use-the-flex-wrap-property-to-wrap-a-row-or-column |
--description--
CSS flexbox 有一個把 flex 子元素拆分爲多行(或多列)的特性。 默認情況下,flex 容器會調整項目大小,把它們都塞到一起。 對於行來說,所有項目都會在一條直線上。
不過,使用 flex-wrap
屬性可以使項目換行展示。 這意味着多出來的子元素會被移到新的行或列。 換行發生的斷點由子元素和容器的大小決定。
換行方向的可選值有這些:
nowrap
:默認值,不換行。wrap
:如果排列以行爲基準,就將行從上往下排列;如果排列以列爲基準,就將列從左往右排列。wrap-reverse
:如果排列以行爲基準,就將行從下往上排列;如果排列以列爲基準,就將列從右往左排列。
--instructions--
現在的佈局中,一行裏面的元素太多了。 請爲 #box-container
元素添加 CSS 屬性 flex-wrap
,把將其屬性值設爲 wrap
。
--hints--
#box-container
元素應具有 flex-wrap
屬性,其屬性值應爲 wrap
。
assert($('#box-container').css('flex-wrap') == 'wrap');
--seed--
--seed-contents--
<style>
#box-container {
background: gray;
display: flex;
height: 100%;
}
#box-1 {
background-color: dodgerblue;
width: 25%;
height: 50%;
}
#box-2 {
background-color: orangered;
width: 25%;
height: 50%;
}
#box-3 {
background-color: violet;
width: 25%;
height: 50%;
}
#box-4 {
background-color: yellow;
width: 25%;
height: 50%;
}
#box-5 {
background-color: green;
width: 25%;
height: 50%;
}
#box-6 {
background-color: black;
width: 25%;
height: 50%;
}
</style>
<div id="box-container">
<div id="box-1"></div>
<div id="box-2"></div>
<div id="box-3"></div>
<div id="box-4"></div>
<div id="box-5"></div>
<div id="box-6"></div>
</div>
--solutions--
<style>
#box-container {
background: gray;
display: flex;
height: 100%;
flex-wrap: wrap;
}
#box-1 {
background-color: dodgerblue;
width: 25%;
height: 50%;
}
#box-2 {
background-color: orangered;
width: 25%;
height: 50%;
}
#box-3 {
background-color: violet;
width: 25%;
height: 50%;
}
#box-4 {
background-color: yellow;
width: 25%;
height: 50%;
}
#box-5 {
background-color: green;
width: 25%;
height: 50%;
}
#box-6 {
background-color: black;
width: 25%;
height: 50%;
}
</style>
<div id="box-container">
<div id="box-1"></div>
<div id="box-2"></div>
<div id="box-3"></div>
<div id="box-4"></div>
<div id="box-5"></div>
<div id="box-6"></div>
</div>