2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 5a858944d96184f06fd60d61
|
2020-12-16 00:37:30 -07:00
|
|
|
|
title: 创建你的第一个 CSS 网格
|
2018-10-10 18:03:03 -04:00
|
|
|
|
challengeType: 0
|
2020-02-11 21:39:15 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/p/pByETK/cqwREC4'
|
|
|
|
|
forumTopicId: 301129
|
2021-01-13 03:31:00 +01:00
|
|
|
|
dashedName: create-your-first-css-grid
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
|
通过将属性 `display` 的值设为 `grid`,HTML 元素就可以变为网格容器。通过前面的操作,你可以对该容器使用与 CSS 网格(CSS Grid)相关的属性。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
|
**注意:**在 CSS 网格中,父元素称为<dfn>容器(container)</dfn>,它的子元素称为<dfn>项(items)</dfn>。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --instructions--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
|
请将 class 为 `container` 的 `div` 的 `display` 属性值设置为 `grid`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
|
class 为 `container` 的 `div` 元素应具有 `display` 属性且属性值应为 `grid`。
|
2020-02-11 21:39:15 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
|
assert(code.match(/.container\s*?{[\s\S]*display\s*?:\s*?grid\s*?;[\s\S]*}/gi));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-02-11 21:39:15 +08:00
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
.d1{background:LightSkyBlue;}
|
|
|
|
|
.d2{background:LightSalmon;}
|
|
|
|
|
.d3{background:PaleTurquoise;}
|
|
|
|
|
.d4{background:LightPink;}
|
|
|
|
|
.d5{background:PaleGreen;}
|
|
|
|
|
|
|
|
|
|
.container {
|
|
|
|
|
font-size: 40px;
|
|
|
|
|
width: 100%;
|
|
|
|
|
background: LightGray;
|
|
|
|
|
/* Only change code below this line */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Only change code above this line */
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<div class="container">
|
|
|
|
|
<div class="d1">1</div>
|
|
|
|
|
<div class="d2">2</div>
|
|
|
|
|
<div class="d3">3</div>
|
|
|
|
|
<div class="d4">4</div>
|
|
|
|
|
<div class="d5">5</div>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --solutions--
|
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
|
```html
|
|
|
|
|
<style>.container {display: grid;}</style>
|
|
|
|
|
```
|