简体   繁体   English

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

[英]Why is my div not in the center of the page?

My result: http://i.imgur.com/P50RS.png My style.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;
}

My index.html 我的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>

Why is the text not centering? 为什么文本不居中? Also, the progress bar was not centering until I added the 此外,在我添加

margin: 0 auto;

I tried that under main but no luck. 我尝试主要,但没有运气。 Any ideas? 有任何想法吗?

In the css, you need to use #main instead of just main . 在CSS中,您需要使用#main而不是main

Also, you'll want to give it some width, otherwise it may take up the entire width. 另外,您需要给它一些宽度,否则它可能会占用整个宽度。 Try this: 尝试这个:

#main {
margin-left: auto;
margin-right: auto;
width: 50%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM