Jump to content

Border positioning


Lambneck

Recommended Posts

Hi, I have an inline unordered list for navigation, and I am using css borders to divide each link. What I want to know is how can I make it so the first list item doesn't have a border to the left of it and the last one doesnt have one to the right of it?

Thanks!

 

#nav {
margin: 0 0 0 400px;
padding: 10px 0 0 0;
}

#nav ul {
list-style-type:none;

}

#nav ul li {
display:inline;

}

#nav ul li a {
font-size:20px;
border-right:1px solid black;
border-left:1px solid white;
color:gray;
margin:0;
padding:0 25px;
}

Link to comment
Share on other sites

You can use the first-child and last-child pseudo classes.

#nav ul li:first-child a {
  border-left: none;
}

#nav ul li:last-child a {
  border-right: none;
}

The last-child pseudo class is CSS 3, but first-child is CSS 2, so test it in many browsers to make sure it is doing what you want it to do.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.