为什么我的div不在页面的中心?

时间:2013-01-12 19:14:22

标签: html css

我的结果:http://i.imgur.com/P50RS.png 我的style.css

body {
background: url("img/bgs.png") repeat #cccccc;
color: #000000;
}


main {
margin-left: auto;
margin-right: auto;
}

我的index.html

<html>
<head>
<title>Progress</title>
<link rel="stylesheet" href="css3-progress-bar.css" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link type="text/css" href="style.css" rel="stylesheet" />
</head>

<body>


<div id="main">
<p><b>215/160 LBS.</b></p>
<div class="bar_mortice rounded green_mortice">
      <div class="progress rounded green" style="width: 05%;"></div>
    </div>
</div>


</body>

</html>

为什么文字不居中?此外,在我添加

之前,进度条没有居中
margin: 0 auto;

我在主要但是没有运气的情况下尝试过。有什么想法吗?

1 个答案:

答案 0 :(得分:5)

在css中,您需要使用#main而不是main

另外,你需要给它一些宽度,否则它可能占用整个宽度。试试这个:

#main {
margin-left: auto;
margin-right: auto;
width: 50%;
}
相关问题