2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: 587d7791367417b2b2512ab3
|
2020-12-16 07:37:30 +00:00
|
|
|
title: 使用 text-align 属性创建视觉平衡
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 0
|
2020-02-11 07:46:34 +00:00
|
|
|
videoUrl: 'https://scrimba.com/c/c3b4EAp'
|
|
|
|
forumTopicId: 301053
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: create-visual-balance-using-the-text-align-property
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
这部分课程的主题是应用视觉设计。开始的挑战基于美化一个卡片组件的外观,借此展示了若干核心原则。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
web 内容大部分都是文本。CSS 里面的 `text-align` 属性可以控制文本的对齐方式。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
`text-align: justify;` 可以让除最后一行之外的文字两端对齐,即每行的左右两端都紧贴行的边缘。
|
|
|
|
|
|
|
|
`text-align: center;` 可以让文本居中对齐。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
`text-align: right;` 可以让文本右对齐。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
`text-align: left;` 是 `text-align` 的默认值,它可以让文本左对齐。
|
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
|
|
|
请让内容文本为 `"Google"` 的 `h4` 标签居中对齐;让介绍了 Google 创立历程的段落文本两端对齐。
|
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
|
|
|
应在 `h4` 标签上使用 text-align 属性设置文本居中对齐。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert($('h4').css('text-align') == 'center');
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
2020-02-11 07:46:34 +00:00
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
应在 `p` 标签上使用 text-align 属性设置文本两端对齐。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert($('p').css('text-align') == 'justify');
|
|
|
|
```
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
h4 {
|
|
|
|
|
|
|
|
}
|
|
|
|
p {
|
|
|
|
|
|
|
|
}
|
|
|
|
.links {
|
|
|
|
margin-right: 20px;
|
|
|
|
|
|
|
|
}
|
|
|
|
.fullCard {
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
border-radius: 5px;
|
|
|
|
margin: 10px 5px;
|
|
|
|
padding: 4px;
|
|
|
|
}
|
|
|
|
.cardContent {
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="fullCard">
|
|
|
|
<div class="cardContent">
|
|
|
|
<div class="cardText">
|
|
|
|
<h4>Google</h4>
|
|
|
|
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
|
|
|
|
</div>
|
|
|
|
<div class="cardLinks">
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
h4 {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
p {
|
|
|
|
text-align: justify;
|
|
|
|
}
|
|
|
|
.links {
|
|
|
|
margin-right: 20px;
|
|
|
|
|
|
|
|
}
|
|
|
|
.fullCard {
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
border-radius: 5px;
|
|
|
|
margin: 10px 5px;
|
|
|
|
padding: 4px;
|
|
|
|
}
|
|
|
|
.cardContent {
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="fullCard">
|
|
|
|
<div class="cardContent">
|
|
|
|
<div class="cardText">
|
|
|
|
<h4>Google</h4>
|
|
|
|
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
|
|
|
|
</div>
|
|
|
|
<div class="cardLinks">
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
```
|