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

1.2 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d78a3367417b2b2512ad0 Center an Element Horizontally Using the margin Property 0 使用margin属性水平居中元素

Description

另一种定位技术是将块元素水平居中。一种方法是将其margin设置为auto值。此方法也适用于图像。默认情况下图像是内联元素但在将display属性设置为block时可以更改为块元素。

Instructions

居中的div通过添加在页面上margin属性与汽车的价值。

Tests

tests:
  - text: <code>div</code>应该有一个设置为auto的<code>margin</code> 。
    testString: 'assert(code.match(/margin:\s*?auto;/g), "The <code>div</code> should have a <code>margin</code> set to auto.");'

Challenge Seed

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

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

Solution

// solution required