2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
id: 5a94fe1369fb03452672e45d
|
2020-12-16 07:37:30 +00:00
|
|
|
|
title: 使用 grid-area 属性将项目放置在网格区域中
|
2018-10-10 22:03:03 +00:00
|
|
|
|
challengeType: 0
|
2020-02-11 13:39:15 +00:00
|
|
|
|
videoUrl: 'https://scrimba.com/p/pByETK/cRrqmtV'
|
|
|
|
|
forumTopicId: 301132
|
2021-01-13 02:31:00 +00:00
|
|
|
|
dashedName: place-items-in-grid-areas-using-the-grid-area-property
|
2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --description--
|
|
|
|
|
|
2021-03-05 15:43:24 +00:00
|
|
|
|
像上一个挑战那样,在为网格添加区域模板后,可以通过引用你所定义的区域的名称,将元素放入相应的区域。 为此,你需要对网格项使用 `grid-area`:
|
2020-02-11 13:39:15 +00:00
|
|
|
|
|
|
|
|
|
```css
|
|
|
|
|
.item1 {
|
|
|
|
|
grid-area: header;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
|
这样,class 为 `item1` 的网格项就被放到了 `header` 区域里。 在这个示例中,网格项将占用第一行整行,因为这一整行都被命名为标题区域。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --instructions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
请使用 `grid-area` 属性,把 class 为 `item5` 的元素放到 `footer` 区域。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --hints--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
|
class 为 `item5` 的元素应具有 `grid-area` 属性且属性值应为 `footer`。
|
2020-02-11 13:39:15 +00:00
|
|
|
|
|
2018-10-10 22:03:03 +00:00
|
|
|
|
```js
|
2021-02-06 04:42:36 +00:00
|
|
|
|
assert(
|
|
|
|
|
__helpers
|
|
|
|
|
.removeCssComments(code)
|
|
|
|
|
.match(/.item5\s*?{[\s\S]*grid-area\s*?:\s*?footer\s*?;[\s\S]*}/gi)
|
|
|
|
|
);
|
2018-10-10 22:03:03 +00:00
|
|
|
|
```
|
2020-02-11 13:39:15 +00:00
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
.item1{background:LightSkyBlue;}
|
|
|
|
|
.item2{background:LightSalmon;}
|
|
|
|
|
.item3{background:PaleTurquoise;}
|
|
|
|
|
.item4{background:LightPink;}
|
|
|
|
|
|
|
|
|
|
.item5 {
|
|
|
|
|
background: PaleGreen;
|
|
|
|
|
/* Only change code below this line */
|
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
|
/* Only change code above this line */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.container {
|
|
|
|
|
font-size: 40px;
|
|
|
|
|
min-height: 300px;
|
|
|
|
|
width: 100%;
|
|
|
|
|
background: LightGray;
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
|
|
|
grid-template-rows: 1fr 1fr 1fr;
|
|
|
|
|
grid-gap: 10px;
|
|
|
|
|
grid-template-areas:
|
|
|
|
|
"header header header"
|
|
|
|
|
"advert content content"
|
|
|
|
|
"footer footer footer";
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<div class="container">
|
|
|
|
|
<div class="item1">1</div>
|
|
|
|
|
<div class="item2">2</div>
|
|
|
|
|
<div class="item3">3</div>
|
|
|
|
|
<div class="item4">4</div>
|
|
|
|
|
<div class="item5">5</div>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --solutions--
|
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
|
```html
|
|
|
|
|
<style>.item5 {grid-area: footer;}</style>
|
|
|
|
|
```
|