---
id: 587d78a3367417b2b2512ad0
title: Center an Element Horizontally Using the margin Property
challengeType: 0
videoUrl: ''
localeTitle: 使用margin属性水平居中元素
---
## Description
另一种定位技术是将块元素水平居中。一种方法是将其margin
设置为auto值。此方法也适用于图像。默认情况下,图像是内联元素,但在将display
属性设置为block时可以更改为块元素。
## Instructions
居中的div
通过添加在页面上margin
属性与汽车的价值。
## Tests
```yml
tests:
- text: div
应该有一个设置为auto的margin
。
testString: 'assert(code.match(/margin:\s*?auto;/g), "The div
should have a margin
set to auto.");'
```
## Challenge Seed
## Solution
```js
// solution required
```