直接上代码:很简单
<div style="width: 200px;height: 200px;margin: 0 auto;background: #007AFF;">左右居中1</div>
<div style="width: 200px;height: 200px;margin: 0 auto;background: #007AFF;">左右居中1</div>
<div style="width: 200px;height: 200px;margin: 0 auto;background: red;position: absolute;left: 0;right: 0;">左右居中2</div>
<div style="width: 200px;height: 200px;margin: auto 0;background: green;position: absolute;top: 0;bottom: 0;">上下居中</div>
<div style="width: 200px;height: 200px;margin: auto auto;background: green;position: absolute;top: 0;bottom: 0;left: 0;right: 0;">上下左右居中</div>