freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-css/add-a-negative-margin-to-an...

1.7 KiB
Raw Blame History

id challengeType videoUrl forumTopicId title
bad87fee1348bd9aedf08823 0 https://scrimba.com/c/cnpyGs3 16166 给元素添加负外边距

Description

元素的margin外边距控制元素border边框与其他周围元素之间的距离大小。 如果你把元素的margin设置为负值,元素会变得更大。

Instructions

尝试将蓝色框的margin设为负值,跟红色框一样大小。 蓝色框的margin设置为-15px,它会填满与黄色框之间的距离。

Tests

tests:
  - text: '<code>blue-box</code> class的<code>margin</code>应该设置为<code>-15px</code>。'
    testString: assert($(".blue-box").css("margin-top") === "-15px");

Challenge Seed

<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;
  }
</style>

<div class="box yellow-box">
  <h5 class="box red-box">padding</h5>
  <h5 class="box blue-box">padding</h5>
</div>

Solution

// solution required