2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: bad87fee1348bd9aedf08823
|
|
|
|
|
challengeType: 0
|
2019-12-13 13:47:57 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/c/cnpyGs3'
|
|
|
|
|
forumTopicId: 16166
|
2020-10-01 17:54:21 +02:00
|
|
|
|
title: 给元素添加负外边距
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<section id='description'>
|
2020-01-08 12:40:17 +08:00
|
|
|
|
元素的<code>margin(外边距)</code>控制元素<code>border(边框)</code>与其他周围元素之间的距离大小。
|
|
|
|
|
如果你把元素的<code>margin</code>设置为负值,元素会变得更大。
|
2019-12-13 13:47:57 +08:00
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<section id='instructions'>
|
2020-01-08 12:40:17 +08:00
|
|
|
|
尝试将蓝色框的<code>margin</code>设为负值,跟红色框一样大小。
|
|
|
|
|
蓝色框的<code>margin</code>设置为<code>-15px</code>,它会填满与黄色框之间的距离。
|
2019-12-13 13:47:57 +08:00
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-01-08 12:40:17 +08:00
|
|
|
|
- text: '<code>blue-box</code> class的<code>margin</code>应该设置为<code>-15px</code>。'
|
|
|
|
|
testString: assert($(".blue-box").css("margin-top") === "-15px");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
|
|
```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;
|
|
|
|
|
}
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
.red-box {
|
|
|
|
|
background-color: crimson;
|
|
|
|
|
color: #fff;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
margin: -15px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.blue-box {
|
|
|
|
|
background-color: blue;
|
|
|
|
|
color: #fff;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
margin: 20px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<div class="box yellow-box">
|
|
|
|
|
<h5 class="box red-box">padding</h5>
|
|
|
|
|
<h5 class="box blue-box">padding</h5>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
2019-12-13 13:47:57 +08:00
|
|
|
|
```html
|
2018-10-10 18:03:03 -04:00
|
|
|
|
// solution required
|
|
|
|
|
```
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</section>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|