2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: 5a94fe2669fb03452672e45e
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 使用 grid-area 创建区域模板
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 0
|
2020-02-11 21:39:15 +08:00
|
|
|
videoUrl: 'https://scrimba.com/p/pByETK/c6N7VhK'
|
|
|
|
forumTopicId: 301135
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
|
|
|
|
|
|
|
你在上一次挑战中学到的`grid-area`属性有另一种使用方式。如果网格中没有定义区域模板,你也可以像这样为它添加一个模板:
|
2020-02-11 21:39:15 +08:00
|
|
|
|
|
|
|
```css
|
|
|
|
item1 { grid-area: 1/1/2/4; }
|
|
|
|
```
|
|
|
|
|
|
|
|
这里使用了你之前学习的网格线编号来定义网格项的区域。上例中数字代表这些值:
|
|
|
|
|
|
|
|
```css
|
|
|
|
grid-area: horizontal line to start at / vertical line to start at / horizontal line to end at / vertical line to end at;
|
|
|
|
```
|
|
|
|
|
|
|
|
因此,示例中的网格项将占用第 1 条水平网格线(起始)和第 2 条水平网格线(终止)之间的行,及第 1 条垂直网格线(起始)和第 4 条垂直网格线(终止)之间的列。
|
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
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
请用`grid-area`属性将类为`item5`的元素放置在第 3 条和第 4 条水平网格线及第 1 条和第 4 条水平网格线之间的区域内。
|
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
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`item5`类应该有`grid-area`属性且值为`3/1/4/4`。
|
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(
|
|
|
|
/.item5\s*?{[\s\S]*grid-area\s*?:\s*?3\s*?\/\s*?1\s*?\/\s*?4\s*?\/\s*?4\s*?;[\s\S]*}/gi
|
|
|
|
)
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-02-11 21:39:15 +08:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|