117 lines
2.1 KiB
Markdown
117 lines
2.1 KiB
Markdown
![]() |
---
|
||
|
id: bad87fee1348bd9aedf08822
|
||
|
title: 調整元素的外邊距
|
||
|
challengeType: 0
|
||
|
videoUrl: 'https://scrimba.com/c/cVJarHW'
|
||
|
forumTopicId: 16654
|
||
|
dashedName: adjust-the-margin-of-an-element
|
||
|
---
|
||
|
|
||
|
# --description--
|
||
|
|
||
|
外邊距 `margin` 用來控制元素的邊框與其他元素之間的 `border` 距離。
|
||
|
|
||
|
在這裏,我們可以看到藍色框和紅色框都在黃色框裏。 請注意,紅色框的 `margin` 值要比藍色框的大,因此紅色框看起來比藍色框要小。
|
||
|
|
||
|
如果你增加藍色的 `margin` 值,它也會增加元素邊框到其他周圍元素的距離。
|
||
|
|
||
|
# --instructions--
|
||
|
|
||
|
請將藍色框的 `margin` 值設置成和紅色框的一樣。
|
||
|
|
||
|
# --hints--
|
||
|
|
||
|
class 爲 `blue-box` 的元素的 `margin` 值應爲 `20px`。
|
||
|
|
||
|
```js
|
||
|
assert($('.blue-box').css('margin-top') === '20px');
|
||
|
```
|
||
|
|
||
|
# --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: 20px;
|
||
|
margin: 20px;
|
||
|
}
|
||
|
|
||
|
.blue-box {
|
||
|
background-color: blue;
|
||
|
color: #fff;
|
||
|
padding: 20px;
|
||
|
margin: 10px;
|
||
|
}
|
||
|
</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>
|
||
|
```
|
||
|
|
||
|
# --solutions--
|
||
|
|
||
|
```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: 20px;
|
||
|
margin: 20px;
|
||
|
}
|
||
|
|
||
|
.blue-box {
|
||
|
background-color: blue;
|
||
|
color: #fff;
|
||
|
padding: 20px;
|
||
|
margin: 20px;
|
||
|
}
|
||
|
</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>
|
||
|
```
|