方案一
| 位置 | 属性名 | 值 | 意义 |
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>水平居中--方案一</title>
<style type="text/css">
/*优点:兼容IE低版本浏览器*/
.parent{ text-align: center; }
.child{display: inline-block;
text-align: left;}
</style>
</head>
<body>
<div class="parent" style="width: 400px;height: 100px;background: red;">
<div class="child" style="width: 80px;height: 100px;background: green;">
<h1>DEMO</h1>
</div>
</div>
</body>
</html> 方案二
| 位置 | 属性名 | 值 | 意义 |