2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 587d78ab367417b2b2512af0
|
|
|
|
|
challengeType: 0
|
2020-02-11 21:32:25 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/p/pVaDAv/cgz3QS7'
|
|
|
|
|
forumTopicId: 301105
|
2020-10-01 17:54:21 +02:00
|
|
|
|
title: '使用 display: flex 定位两个盒子'
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2020-02-11 21:32:25 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
这节会使用一种不同的挑战方式来学习一下如何使用 CSS 更灵活地布局元素。首先通过一个挑战来理解原理,然后通过操作一个简单的推文组件来应用“弹性盒子”(flexbox)。
|
|
|
|
|
只要在一个元素的 CSS 中添加<code>display: flex;</code>,就可以使用其它 flex 属性来构建响应式页面了。
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2020-02-11 21:32:25 +08:00
|
|
|
|
<section id='instructions'>
|
2020-03-03 22:41:15 +09:00
|
|
|
|
为<code>#box-container</code>添加<code>display</code>属性,设置其值为 <code>flex</code>。
|
2020-02-11 21:32:25 +08:00
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-03-03 22:41:15 +09:00
|
|
|
|
- text: <code>#box-container</code>应有<code>display</code>属性,其值应为 <code>flex</code>。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert($('#box-container').css('display') == 'flex');
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
#box-container {
|
|
|
|
|
height: 500px;
|
2020-02-11 21:32:25 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
}
|
2020-02-11 21:32:25 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
#box-1 {
|
|
|
|
|
background-color: dodgerblue;
|
|
|
|
|
width: 50%;
|
|
|
|
|
height: 50%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#box-2 {
|
|
|
|
|
background-color: orangered;
|
|
|
|
|
width: 50%;
|
|
|
|
|
height: 50%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
<div id="box-container">
|
|
|
|
|
<div id="box-1"></div>
|
|
|
|
|
<div id="box-2"></div>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
2020-02-11 21:32:25 +08:00
|
|
|
|
```html
|
2018-10-10 18:03:03 -04:00
|
|
|
|
// solution required
|
|
|
|
|
```
|
2020-02-11 21:32:25 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</section>
|
2020-02-11 21:32:25 +08:00
|
|
|
|
|