2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 5a90374338fddaf9a66b5d3a
|
2020-12-16 00:37:30 -07:00
|
|
|
|
title: 使用 justify-self 水平对齐项目
|
2018-10-10 18:03:03 -04:00
|
|
|
|
challengeType: 0
|
2020-02-11 21:39:15 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/p/pByETK/cJbpKHq'
|
|
|
|
|
forumTopicId: 301122
|
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
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
在 CSS 网格中,每个网格项的内容分别位于被称为<dfn>单元格(cell)</dfn>的框内。你可以使用网格项的`justify-self`属性,设置其内容的位置在单元格内沿行轴对齐的方式。默认情况下,这个属性的值是`stretch`,这将使内容占满整个单元格的宽度。该 CSS 网格属性也可以使用其他的值:
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`start`:使内容在单元格左侧对齐,
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`center`:使内容在单元格居中对齐,
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`end`:使内容在单元格右侧对齐,
|
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
|
|
|
|
使用`justify-self`属性让类为`item2`的网格项居中。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --hints--
|
2020-02-11 21:39:15 +08:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`item2`类应该有`justify-self`属性且值为`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(/.item2\s*?{[\s\S]*justify-self\s*?:\s*?center\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--
|
|
|
|
|
|