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
https://forums.phpfreaks.com/topic/262336-border-positioning/
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
https://forums.phpfreaks.com/topic/262336-border-positioning/#findComment-1346062
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.