Files
freeCodeCamp/curriculum/challenges/japanese/01-responsive-web-design/basic-css/add-different-margins-to-each-side-of-an-element.md
2022-01-20 20:30:18 +01:00

2.8 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-top, margin-right, margin-bottom, margin-left のプロパティを使用して、要素の 4 つの辺それぞれの margin を制御することができます。

--instructions--

青い四角の margin を上側と左側は 40px、下側と右側は 20px に設定してください。

--hints--

blue-box クラスは、要素の上側に 40pxmargin を与える必要があります。

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

blue-box クラスは、要素の右側に 20pxmargin を与える必要があります。

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

blue-box クラスは、要素の下側に 20pxmargin を与える必要があります。

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

blue-box クラスは、要素の左側に 40pxmargin を与える必要があります。

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>