2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: 5a90376038fddaf9a66b5d3c
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 使用 justify-items 水平对齐所有项目
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 0
|
2020-02-11 21:39:15 +08:00
|
|
|
videoUrl: 'https://scrimba.com/p/pByETK/cJbpECn'
|
|
|
|
forumTopicId: 301120
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: align-all-items-horizontally-using-justify-items
|
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-08-25 09:12:11 -07:00
|
|
|
有时你想让 CSS 网格中的网格项共享对齐方式。 你可以像之前学习的那样分别设置它们的对齐方式,也可以对网格容器使用 `justify-items` 使它们一次性沿水平轴对齐。 这个属性能接受我们在之前两个挑战中学到的所有值作为属性值,但与之前不同的是,它会将网格中 **所有** 的网格项按所设置的方式对齐。
|
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-02-06 04:42:36 +00:00
|
|
|
请使用这个属性设置所有网格项水平居中。
|
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` 的元素应具有 `justify-items` 属性且属性值应为 `center`。
|
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]*justify-items\s*?:\s*?center\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>
|
|
|
|
.item1{background:LightSkyBlue;}
|
|
|
|
.item2{background:LightSalmon;}
|
|
|
|
.item3{background:PaleTurquoise;}
|
|
|
|
.item4{background:LightPink;}
|
|
|
|
.item5{background:PaleGreen;}
|
|
|
|
|
|
|
|
.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;
|
|
|
|
/* Only change code below this line */
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
/* Only change code above this line */
|
|
|
|
}
|
|
|
|
</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 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
```html
|
|
|
|
<style>.container {justify-items: center;}</style>
|
|
|
|
```
|