<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>为什么text-align:center无法将div水平居中-蚂蚁部落</title>
<style type="text/css">
div{
width:700px;
height:700px;
font-size: 30px;
background-color:green;
}
#children{
padding-top: 60px;
width: 600px;
height: 400px;
background-color: red;
margin: 0px auto;
text-align: center;
font-size: 30px;
}
</style>
</head>
<body>
<h1 >'margin: 0px auto;让div 左右居中' </h1>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>为什么text-align:center无法将div水平居中-蚂蚁部落</title>
<style type="text/css">
div{
width:700px;
height:700px;
font-size: 30px;
background-color:green;
}
#children{
padding-top: 60px;
width: 600px;
height: 400px;
background-color: red;
margin: 0px auto;
text-align: center;
font-size: 30px;
}
</style>
</head>
<body>
<h1 >'margin: 0px auto;让div 左右居中' </h1>
<h1 >'text-align: center;让div里面的文本或图片左右居中' </h1>
<div style="margin: 0px auto;"> 绿色我是父div
<div id="children">
<p >我是子div的文本,我居中 </p>
</div>
</div>
</body>