2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: 5a90373638fddaf9a66b5d39
|
|
|
|
title: Use grid-row to Control Spacing
|
|
|
|
challengeType: 0
|
2020-02-11 21:39:15 +08:00
|
|
|
videoUrl: 'https://scrimba.com/p/pByETK/c9WBLU4'
|
|
|
|
forumTopicId: 301137
|
|
|
|
localeTitle: 使用 grid-row 来控制空间大小
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-02-11 21:39:15 +08:00
|
|
|
<section id='description'>
|
|
|
|
当然,和设置一个网格项占用多列一样,你也可以设置它占用多行。你可以使用<code>grid-row</code>属性来定义一个网格项开始和结束的水平线。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
2020-02-11 21:39:15 +08:00
|
|
|
<section id='instructions'>
|
|
|
|
使类为<code>item5</code>的元素占用最后两行。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
2020-02-11 21:39:15 +08:00
|
|
|
- text: '<code>item5</code>类应该有<code>grid-row</code>属性且值为<code>2 / 4</code>。'
|
|
|
|
testString: 'assert(code.match(/.item5\s*?{[\s\S]*grid-row\s*?:\s*?2\s*?\/\s*?4\s*?;[\s\S]*}/gi));'
|
|
|
|
- text: '<code>item5</code> class 应该有 <code>grid-row</code> 属性使其占用网格最后两行。'
|
|
|
|
testString: "
|
|
|
|
const rowStart = getComputedStyle($('.item5')[0]).gridRowStart;
|
|
|
|
const rowEnd = getComputedStyle($('.item5')[0]).gridRowEnd;
|
|
|
|
const result = rowStart.toString() + rowEnd.toString();
|
|
|
|
const correctResults = ['24', '2-1', '2span 2', '2span2', 'span 2-1', '-12', 'span 2span 2', 'span 2auto', 'autospan 2'];
|
|
|
|
assert(correctResults.includes(result));
|
|
|
|
"
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
.item1{background:LightSkyBlue;}
|
|
|
|
.item2{background:LightSalmon;}
|
|
|
|
.item3{background:PaleTurquoise;}
|
|
|
|
.item4{background:LightPink;}
|
2020-02-11 21:39:15 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
.item5 {
|
|
|
|
background: PaleGreen;
|
|
|
|
grid-column: 2 / 4;
|
2020-02-11 21:39:15 +08:00
|
|
|
/* 请在本行以下添加你的代码 */
|
|
|
|
|
|
|
|
|
|
|
|
/* 请在本行以上添加你的代码 */
|
2018-10-10 18:03:03 -04:00
|
|
|
}
|
2020-02-11 21:39:15 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
.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;
|
|
|
|
}
|
|
|
|
</style>
|
2020-02-11 21:39:15 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
<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>
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
2020-02-11 21:39:15 +08:00
|
|
|
```html
|
2018-10-10 18:03:03 -04:00
|
|
|
// solution required
|
|
|
|
```
|
2020-02-11 21:39:15 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
</section>
|
2020-02-11 21:39:15 +08:00
|
|
|
|