CSS列表边框底部间距问题

时间:2013-07-17 18:43:59

标签: php html css navbar

我遇到了这个CSS的问题,我似乎无法找到它。

我有一点PHP:

<ul>
<?php if($page=="home"){echo"<li class='active'>";}else{echo"<li>";}?><a href="http://www.trevorpeyton.com/" alt="Home page">Home</a></li> 
<?php if($page=="about"){echo"<li class='active'>";}else{echo"<li>";}?><li><a href="http://www.trevorpeyton.com/about/" alt="Learn all about me">About</a></li> 
<?php if($page=="contact"){echo"<li class='active'>";}else{echo"<li>";}?><li><a href="http://www.trevorpeyton.com/contact/" alt="Contact me">Contact</a></li> 
<?php if($page=="projects"){echo"<li class='active'>";}else{echo"<li>";}?><li><a href="http://www.trevorpeyton.com/projects/"alt="View projects I am working on/completed">Projects</a></li> 
<?php if($page=="sites"){echo"<li class='active'>";}else{echo"<li>";}?><li><a href="http://www.trevorpeyton.com/sites/" alt="View websites I have made">Sites</a></li> 
<?php if($page=="demo"){echo"<li class='active'>";}else{echo"<li>";}?><li><a href="http://www.trevorpeyton.com/demo/" alt="Demo the new user features">Demo</a></li> 
</ul> 

现在,在每个页面上,它将定义$page。问题是当页面处于活动状态时,它会在项目下方显示一个栏。栏位于页面右侧,主页位于最右侧。如果那个是活跃的,那么它的工作正常。当任何其他项目处于活动状态时,该行位于左侧。这是我的CSS:

#header {
position:fixed;
background:#222;
color:#999;
width:100%;
margin:0px;
padding:0px;
top:0;
z-index:1;
height:5%;
}
#header ul li{
display: inline;
margin:0;
float:right;
display:block;
padding:5px 10px;
}
#header .active{
border-bottom: solid 3px orange;
}

Right

错误

Wrong

我知道它与间距有关,但我无法弄明白。我不是一个CSS人。

1 个答案:

答案 0 :(得分:4)

我猜您输出的内容超过了所需的<li>代码

<?php if($page=="demo"){echo"<li class='active'>";}else{echo"<li>";}?><li><a href="http://www.trevorpeyton.com/demo/" alt="Demo the new user features">Demo</a></li> 

这将输出

<li class='active'>
   <li><a href="http://www.trevorpeyton.com/demo/" alt="Demo the new user features">Demo</a></li> 

<li>
   <li><a href="http://www.trevorpeyton.com/demo/" alt="Demo the new user features">Demo</a></li> 

因此,要查看这是否是问题,请使用此

<ul>
    <?php if($page=="home"){echo"<li class='active'>";}else{echo"<li>";}?><a href="http://www.trevorpeyton.com/" alt="Home page">Home</a></li> 
    <?php if($page=="about"){echo"<li class='active'>";}else{echo"<li>";}?><a href="http://www.trevorpeyton.com/about/" alt="Learn all about me">About</a></li> 
    <?php if($page=="contact"){echo"<li class='active'>";}else{echo"<li>";}?><a href="http://www.trevorpeyton.com/contact/" alt="Contact me">Contact</a></li> 
    <?php if($page=="projects"){echo"<li class='active'>";}else{echo"<li>";}?><a href="http://www.trevorpeyton.com/projects/"alt="View projects I am working on/completed">Projects</a></li> 
    <?php if($page=="sites"){echo"<li class='active'>";}else{echo"<li>";}?><a href="http://www.trevorpeyton.com/sites/" alt="View websites I have made">Sites</a></li> 
    <?php if($page=="demo"){echo"<li class='active'>";}else{echo"<li>";}?><a href="http://www.trevorpeyton.com/demo/" alt="Demo the new user features">Demo</a></li> 
</ul>