简体   繁体   English

CSS列表边框底部间距问题

[英]CSS list border bottom spacing issue

I am having issues with this bit of CSS and I can't seem to find it out. 我在使用CSS时遇到问题,似乎无法找出答案。

I have a bit of PHP: 我有一些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> 

Now, on each page it will define $page . 现在,在每个页面上将定义$page The issue is when a page is active it displays a bar underneath the item. 问题是当页面处于活动状态时,它会在项目下方显示一个栏。 The bar is floating to the right side of the page and the home item is on the far right. 条形图浮动在页面的右侧,而主页项在最右侧。 If that one is active then it works just fine. 如果那个是活跃的,那它就很好了。 When any of the other items are active then the line is to the left. 当任何其他项目处于活动状态时,该行位于左侧。 Here is my CSS: 这是我的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 错误

错误

I know it has something to do with the spacing but I just can't figure it out. 我知道这与间距有关,但是我无法弄清楚。 I'm not a CSS guy. 我不是CSS专家。

I am guessing that you are outputting more than the needed <li> tags 我猜您输出的内容超出了所需的<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> 

this will either output 这将输出

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

or 要么

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

So to see if this is the problem use this 所以看看这是不是问题

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM