Home  >  Article  >  Web Front-end  >  求助:为何中间的导航条无法居中?_html/css_WEB-ITnose

求助:为何中间的导航条无法居中?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:09:51932browse

中间的导航条无论如何都不能居中 ?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:




nbsp;html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
test1













  
  


 













回复讨论(解决方案)

你是在哪个浏览器下面看的?

我看了IE6/7/8没跑啊!

在firefox3.6和IE7下都不行啊.
#navbar 在两个浏览器下都是靠左的。

我没看见靠左    可能你的空行太多了  你应用原格式看看!

还是不行啊,楼上的能不能留个QQ教我下?

dtd ? html 前面 ,文?的第一行……

TO 楼上
在Dreamweaver里copy了这么一段,但还是不行..郁闷...
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd">


charset=gb2312" 改成 charset=utf-8"

检查你的标签是否配对,书写是否正确,例如下面这个嵌套就是错误的。



    的子元素只能是
  • body里面margin: 0px  auto

    呃..问题还是没解决..先自己多看看书再来提问,谢谢各位的回答了!

    #navbar ul li a {
    padding:0 5px 0 5px;
    height:30px;/*你这里我给你写的具体值,你可以跟100%*/
    float:left;
    text-decoration:none;
    background:#FFE1FF;
    color:black;
    line-height:1.5 em;这是你的源代码。在line-height里面;你给单位打了空格无效,出去空格,将值改为1.7em就可以,这样出现;
    #navbar ul {
    list-style-type:none;
    background:;
    width:200px;
    margin:0 auto;
    height:30px;看这个我给你把宽固定了才行,ul是块级元素你给它宽和他的父级元素一样大了。你在夫级里面只是控制到里面的容器,对内容没控制到,除非你重新布局安排ul;好早的帖子,可能对你都没用了;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn