2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
id: bad87fee1348bd9aedf08823
|
|
|
|
title: Add a Negative Margin to an Element
|
|
|
|
challengeType: 0
|
|
|
|
videoUrl: 'https://scrimba.com/c/cnpyGs3'
|
2019-07-31 18:32:23 +00:00
|
|
|
forumTopicId: 16166
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: add-a-negative-margin-to-an-element
|
2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --description--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
An element's `margin` controls the amount of space between an element's `border` and surrounding elements.
|
|
|
|
|
|
|
|
If you set an element's `margin` to a negative value, the element will grow larger.
|
|
|
|
|
|
|
|
# --instructions--
|
|
|
|
|
|
|
|
Try to set the `margin` to a negative value like the one for the red box.
|
|
|
|
|
|
|
|
Change the `margin` of the blue box to `-15px`, so it fills the entire horizontal width of the yellow box around it.
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
|
|
Your `blue-box` class should give elements `-15px` of `margin`.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert($('.blue-box').css('margin-top') === '-15px');
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --seed--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
## --seed-contents--
|
2018-09-30 22:01:58 +00: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;
|
|
|
|
}
|
2018-10-08 00:01:53 +00:00
|
|
|
|
2018-09-30 22:01:58 +00: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>
|
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --solutions--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2018-10-23 13:21:53 +00: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: 20px;
|
|
|
|
margin: -15px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.blue-box {
|
|
|
|
background-color: blue;
|
|
|
|
color: #fff;
|
|
|
|
padding: 20px;
|
|
|
|
margin: 20px;
|
|
|
|
margin-top: -15px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<div class="box yellow-box">
|
|
|
|
<h5 class="box red-box">padding</h5>
|
|
|
|
<h5 class="box blue-box">padding</h5>
|
|
|
|
</div>
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|