freeCodeCamp/curriculum/challenges/japanese/01-responsive-web-design/applied-visual-design/center-an-element-horizonta...

1.3 KiB

id title challengeType videoUrl forumTopicId dashedName
587d78a3367417b2b2512ad0 margin プロパティで要素を水平方向の中央に配置する 0 https://scrimba.com/c/cyLJqU4 301043 center-an-element-horizontally-using-the-margin-property

--description--

次のテクニックは、ブロック要素を水平方向の中央に配置する方法です。 これを行う一つの方法は、margin の値を auto に設定することです。

この方法は画像に対しても使うことができます。 画像はデフォルトではインライン要素ですが、display プロパティを block に設定すると、ブロック要素に変更できます。

--instructions--

値が automargin プロパティを追加して、div を中央に表示させてください。

--hints--

divmargin の値は auto に設定される必要があります。

assert(new __helpers.CSSHelp(document).getStyle('div')?.margin === 'auto');

--seed--

--seed-contents--

<style>
  div {
    background-color: blue;
    height: 100px;
    width: 100px;

  }
</style>
<div></div>

--solutions--

<style>
  div {
    background-color: blue;
    height: 100px;
    width: 100px;
    margin: auto;
  }
</style>
<div></div>