[英]Why is my div not in the center of the page?
我的結果: 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;
我嘗試主要,但沒有運氣。 有任何想法嗎?
在CSS中,您需要使用#main
而不是main
。
另外,您需要給它一些寬度,否則它可能會占用整個寬度。 嘗試這個:
#main {
margin-left: auto;
margin-right: auto;
width: 50%;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.