日期:2014-05-17  浏览次数:20729 次

求助:为何中间的导航条无法居中?
中间的导航条无论如何都不能居中 囧rz..本人刚开始学html和css,菜鸟一个,望各位高手能指点一二,谢谢!


css代码:

body {
background:#efefef;
text-align:center;
margin:0;
padding:0;
}

#main {
width:950px;
background:#fffacd;
margin:0 auto;
padding:0;
}

#header {
background:#0ff ;
height:180px;
width:950px;
margin:0 auto;
text-align:center;
}

#logo {
background:#044 url(logo.jpg) no-repeat;
width:950px;
height:150px;
margin:0;
padding:0;
}

/********************navbar******************/


#navbar {
margin:0 auto;
padding:0;
background:#ccc;
width:auto;
height:30px;
text-align:center;
}

#navbar ul {
list-style-type:none;
background:#CDB7B5;
width:auto;
margin:0 auto;
padding:0 auto;
height:30px;
clear:both;
}

#navbar ul li {
display:block;
float:left;
width:auto;
  text-align:center;
}

#navbar ul li a {
padding:0 5px 0 5px;
height:30px;
float:left;
text-decoration:none;
background:#FFE1FF;
color:black;
line-height:1.5 em;

}

#navbar ul li a:hover {
color:#9C9C9C;
background:#CAE1FF;
}

#navbar .fg {
float:left;
width:1px;
height:30px;
background:black;
}

/********************************************/
#content {
background:#ffffe0;
width:950px;
padding:auto;
margin:auto;
overflow:hidden;
}

#footer {
background:#fff0f5;
width:950px;
height:100px;
padding:0;
margin:auto;
clear:both;
}

/*content内容 left,mid,right */
#left {
margin:0;
float:left;
width:200px;
}

#mid {
background:#0f0;
margin-top:0;
margin-left:4px;
float:left;
padding:0 auto;
width:562px;
height:250px;
}

#right {
background:#00f;
margin:0;
float:right;
width:180px;
padding:auto;
}


HTML:


<html>
<head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<title>test1</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="main">
<div id="header">

<div id="logo">
</div>

<div id="navbar">


<ul>
<li><a href="as">sdahg</a></li>
<div class="fg"></div>
<li><a href="as">sdahg</a></li>
<div class="fg"></div>


</ul>
 


</div> 


</div>

<div id="content">
<div id="left">
<div id="leftnav">
<h2>adsfadsf</h2>
<ul>
<li><a href="aa">ffff</a></li>
<li><a href="aa">akgha</a></li>
<li><a href="aa">adsga</a></li>
<li><a href="aa">daghad</a></li>
<li><a href="aa">ahgad</a></li>
<li><a href="aa">dagha</a>