HTML中的DIV怎么居中,求,急!!!请直接修改代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>刺客信条</title>
<style type="text/css">

#nav {margin-top:0px; background-color:#000000; width:725px; height:50px; position:fixed; margin-right:auto; margin-left:auto;}
body{background:url(image/anybackgroud.jpg); text-align:center;}
</style>
</head>

<body><center>
<div id="me">
<a href="index.html"><img src="image/me.gif" width="100" height="100" border="0" /></a>
</div>
<a href="index.html"><img src="image/logo.jpg" style=" position:fixed; left:141px; top:60px;" height="100" width="100" alt="logo" border="0"/></a>
<div id="nav">

</div>
<div class="vip">

</div>
<div id="principal">

</div>
<img src="image/indexdown.jpg" width="600" height="300" />
<div id="footer">
<div class="foot">
<p><span>
</br>
© 2</span> </p>
</div>
</div>
</center></body>

</html>
麻烦回答的各位先试一下有没有用再回答

DIV居中提供两个方法:

1、简单快捷方法就是加<center>内容</center>标签。

示例:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>center居中</title>
</head>

<body>
<center>
<div>我要居中啦</div>
</center>
</body>
</html>

2、div中加入margin:0 auto属性;自动调节居中。

示例:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>margin居中</title>
<style type="text/css">
.d1{
border:1px solid red;
width:200px;
height:200px;
text-align:center;
line-height:40px;
margin:0 auto;
}
</style>
</head>
<body>
<div class="d1">
我是div,我居中啦...
</div>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-04-15
#nav {
margin-top: 0px;
margin-bottom: 0px;
background-color: #000000;
width: 725px;
height: 50px;
margin-right: auto;
margin-left: auto;
}追问

没用

第2个回答  2014-04-16
<div id="nav" align="center"></div>追问

没用

第3个回答  2014-04-16
nav必须得用position:fixed;吗,把它去掉就好了追问

没用

追答

我试了有用啊,你是要这种不?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>刺客信条</title>

<style type="text/css">

#nav { margin-top:0px; background-color:#000000; width:725px; height:50px; margin-right:auto; margin-left:auto; }

body { background:url(image/anybackgroud.jpg); text-align:center; }

</style>

</head>

<body>

<center>

<div id="me"> <a href="index.html"><img src="image/me.gif" width="100" height="100" border="0" /></a> </div>

<a href="index.html"><img src="image/logo.jpg" style=" position:fixed; left:141px; top:60px;" height="100" width="100" alt="logo" border="0"/></a>

<div id="nav"> </div>

<div class="vip"> </div>

<div id="principal"> </div>

<img src="image/indexdown.jpg" width="600" height="300" />

<div id="footer">

<div class="foot">

<p><span> </br>

© 2</span> </p>

</div>

</div>

</center>

</body>

</html>

本回答被提问者采纳
第4个回答  2014-04-16
是nav这个div居中吗
需要div固定,用到position: fixed。
#nav {
background-color: #000000;
width: 725px;
height: 50px;
position: fixed;
top: 0px;
left: 50%;
margin-left: -362px;
}
不需要div固定,去掉position: fixed
#nav {
background-color: #000000;
width: 725px;
height: 50px;
margin:0 auto;
}追问

没用

相似回答