简体   繁体   中英

CSS list border bottom spacing issue

I am having issues with this bit of CSS and I can't seem to find it out.

I have a bit of 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 . 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:

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

I am guessing that you are outputting more than the needed <li> tags

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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