2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: bad87fee1348bd9aedf08824
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 给元素的每一侧添加不同的内边距
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 0
|
2019-12-13 13:47:57 +08:00
|
|
|
videoUrl: 'https://scrimba.com/c/cB7mwUw'
|
|
|
|
forumTopicId: 16634
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: add-different-padding-to-each-side-of-an-element
|
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-01-08 11:20:48 -08:00
|
|
|
有时候,你会想给一个元素每个方向的 `padding` 都设置一个特定的值
|
2020-12-16 00:37:30 -07:00
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
CSS 允许你使用 `padding-top`、`padding-right`、`padding-bottom`、`padding-left` 属性来设置四个不同方向的 `padding` 值。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
# --instructions--
|
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
请将蓝色框的顶部和左侧 `padding` 属性值设置为 `40px`;将底部和右侧的属性值设置为 `20px`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
class 为 `blue-box` 的元素的上内边距属性值应为 `40px`。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert($('.blue-box').css('padding-top') === '40px');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
class 为 `blue-box` 的元素的右内边距属性值应为 `20px`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert($('.blue-box').css('padding-right') === '20px');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
class 为 `blue-box` 的元素的下内边距属性值应为 `20px`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert($('.blue-box').css('padding-bottom') === '20px');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-01-08 11:20:48 -08:00
|
|
|
class 为 `blue-box` 的元素的左内边距属性值应为 `40px`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert($('.blue-box').css('padding-left') === '40px');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-02-18 01:40:55 +09:00
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
.injected-text {
|
|
|
|
margin-bottom: -25px;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.box {
|
|
|
|
border-style: solid;
|
|
|
|
border-color: black;
|
|
|
|
border-width: 5px;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.yellow-box {
|
|
|
|
background-color: yellow;
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.red-box {
|
|
|
|
background-color: crimson;
|
|
|
|
color: #fff;
|
|
|
|
padding-top: 40px;
|
|
|
|
padding-right: 20px;
|
|
|
|
padding-bottom: 20px;
|
|
|
|
padding-left: 40px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.blue-box {
|
|
|
|
background-color: blue;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<h5 class="injected-text">margin</h5>
|
|
|
|
|
|
|
|
<div class="box yellow-box">
|
|
|
|
<h5 class="box red-box">padding</h5>
|
|
|
|
<h5 class="box blue-box">padding</h5>
|
|
|
|
</div>
|
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
.injected-text {
|
|
|
|
margin-bottom: -25px;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.box {
|
|
|
|
border-style: solid;
|
|
|
|
border-color: black;
|
|
|
|
border-width: 5px;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.yellow-box {
|
|
|
|
background-color: yellow;
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.red-box {
|
|
|
|
background-color: crimson;
|
|
|
|
color: #fff;
|
|
|
|
padding-top: 40px;
|
|
|
|
padding-right: 20px;
|
|
|
|
padding-bottom: 20px;
|
|
|
|
padding-left: 40px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.blue-box {
|
|
|
|
background-color: blue;
|
|
|
|
color: #fff;
|
|
|
|
padding-top: 40px;
|
|
|
|
padding-right: 20px;
|
|
|
|
padding-bottom: 20px;
|
|
|
|
padding-left: 40px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<h5 class="injected-text">margin</h5>
|
|
|
|
|
|
|
|
<div class="box yellow-box">
|
|
|
|
<h5 class="box red-box">padding</h5>
|
|
|
|
<h5 class="box blue-box">padding</h5>
|
|
|
|
</div>
|
|
|
|
```
|