Files
freeCodeCamp/curriculum/challenges/chinese-traditional/01-responsive-web-design/basic-css/add-different-margins-to-each-side-of-an-element.md
Nicholas Carrigan (he/him) 3da4be21bb chore: seed chinese traditional (#42005)
Seeds the chinese traditional files manually so we can deploy to
staging.
2021-05-05 22:43:49 +05:30

2.6 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
bad87fee1248bd9aedf08824 給元素的每一側添加不同的外邊距 0 https://scrimba.com/c/cg4RWh4 16633 add-different-margins-to-each-side-of-an-element

--description--

有時候,你會想給一個元素每個方向的 margin 都設置成一個特定的值。

CSS 允許你使用 margin-topmargin-rightmargin-bottommargin-left 屬性來設置四個不同方向的 margin 值。

--instructions--

請將藍色框的頂部和左側 margin 屬性值設置爲 40px,將底部和右側的屬性值設置爲 20px

--hints--

class 爲 blue-box 的元素的上外邊距屬性值 margin 應爲 40px

assert($('.blue-box').css('margin-top') === '40px');

class 爲 blue-box 的元素的右外邊距屬性值 margin 應爲 20px

assert($('.blue-box').css('margin-right') === '20px');

class 爲 blue-box 的元素的下外邊距屬性值 margin 應爲 20px

assert($('.blue-box').css('margin-bottom') === '20px');

class 爲 blue-box 的元素的左外邊距屬性值 margin 應爲 40px

assert($('.blue-box').css('margin-left') === '40px');

--seed--

--seed-contents--

<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;
    margin-top: 40px;
    margin-right: 20px;
    margin-bottom: 20px;
    margin-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>

--solutions--

<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;
    margin-top: 40px;
    margin-right: 20px;
    margin-bottom: 20px;
    margin-left: 40px;
  }

  .blue-box {
    background-color: blue;
    color: #fff;
    margin-top: 40px;
    margin-right: 20px;
    margin-bottom: 20px;
    margin-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>