1

I am trying to have a menu navigation like this:

start fire | our fires | past fires

I want the menu items to be separated by vertical lines as opposed to spaces

<ul class="standard-nav visible-lg">
    <li><a id="intro-linker" class="scroll" href="#intro">Start a fire</a></li>
    <li><a id="about-linker" class="scroll" href="#ourfires">Our fire</a></li>
    <li><a id="services-linker" class="scroll" href="#pastfires">Past fires</a></li>
    <li><a id="team-linker" class="scroll" href="#team">Chief fire lighter</a></li>
    <li><a id="portfolio-linker" class="scroll" href="#seriesfires">Series of fires</a></li>
    <li><a id="contact-linker" class="scroll" href="#contact">Get fired up</a></li>
</ul>

The css is here:

.standard-nav{
    list-style: none;
    padding: 0;
    margin: 0;
    margin-top: 25px;
    float: right;
}
.standard-nav li{
    display: inline-block;
    float: left;
    margin-left: 10px;
    margin-right: 10px;
}    
.standard-nav li > a{
    color: #ffffff;
    font-family: "Vegur Light";
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.15em;
    line-height:19px;
    /*text-transform: uppercase;*/
}
ryanyuyu
  • 6,366
  • 10
  • 48
  • 53
Billeh Sarkozy
  • 53
  • 1
  • 3
  • 11
  • jQuery UI tabs could work, but are overkill; [this answer](http://stackoverflow.com/a/11574821/410342) is a decent CSS-only example. Fiddle: https://jsfiddle.net/A52T8/234/ – Shotgun Ninja Jun 30 '15 at 14:27

4 Answers4

7

You can use pseudo-element :after alongside :not(:last-child) to not apply this to last element:

ul li {
  display: inline-block;
}

ul li:not(:last-child):after {
  content: "|";
  }
<ul class="standard-nav visible-lg">
  <li><a id="intro-linker" class="scroll" href="#intro">Start a fire</a>
  </li>
  <li><a id="about-linker" class="scroll" href="#ourfires">Our fire</a>
  </li>
  <li><a id="services-linker" class="scroll" href="#pastfires">Past fires</a>
  </li>
  <li><a id="team-linker" class="scroll" href="#team">Chief fire lighter</a>
  </li>
  <li><a id="portfolio-linker" class="scroll" href="#seriesfires">Series of fires</a>
  </li>
  <li><a id="contact-linker" class="scroll" href="#contact">Get fired up</a>
  </li>

</ul>

For IE8 support reverse the logic of css rule:

ul li {
  display: inline-block;
}
ul li:not(:first-child):before {
  content: "|";
}
<ul class="standard-nav visible-lg">
  <li><a id="intro-linker" class="scroll" href="#intro">Start a fire</a>
  </li>
  <li><a id="about-linker" class="scroll" href="#ourfires">Our fire</a>
  </li>
  <li><a id="services-linker" class="scroll" href="#pastfires">Past fires</a>
  </li>
  <li><a id="team-linker" class="scroll" href="#team">Chief fire lighter</a>
  </li>
  <li><a id="portfolio-linker" class="scroll" href="#seriesfires">Series of fires</a>
  </li>
  <li><a id="contact-linker" class="scroll" href="#contact">Get fired up</a>
  </li>

</ul>

References

:after

:not

:last-child

Alex Char
  • 32,879
  • 9
  • 49
  • 70
  • so i do away with the css completely – Billeh Sarkozy Jun 30 '15 at 14:25
  • @BillehSarkozy If I understand right, yes you can do it with pure css. – Alex Char Jun 30 '15 at 14:29
  • Since [IE8 supports `:first-child` but not `:last-child`](http://stackoverflow.com/questions/7938521/browser-support-for-css-first-child-and-last-child), I prefer to place the pipe character `:before` every list item and then override it for `:first-child`. – Blazemonger Jun 30 '15 at 14:44
  • @Blazemonger thanks for the feedback. Updated. To be honest I never have IE8 in mind. – Alex Char Jun 30 '15 at 14:50
2

Use CSS border:

.standard-nav li {
    border-right: 1px solid red;
}
.standard-nav li:last-child {
    border: none;
}

DEMO

Shorter

.standard-nav li:not(:last-child) {
    border-right: 1px solid red;
}

DEMO

Tushar
  • 85,780
  • 21
  • 159
  • 179
0

You may see this Fiddle Demo.

Whole HTML code:

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<style>
.standard-nav{
    list-style: none;
    padding: 0;
    margin: 0;
    margin-top: 25px;
    float: right;
}
.standard-nav li{
    border-right: 2px solid #c4c4c4;
    display: inline-block;
    float: left;
    padding: 0 15px;
}
.standard-nav li:last-child {
    border-right:0;
} 
.standard-nav li > a{
    color: red;
    font-family: "Vegur Light";
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.15em;
    line-height:19px;
    /*text-transform: uppercase;*/
}
</style>
</head>
<body>
<ul class="standard-nav visible-lg">
    <li><a id="intro-linker" class="scroll" href="#intro">Start a fire</a></li>
    <li><a id="about-linker" class="scroll" href="#ourfires">Our fire</a></li>
    <li><a id="services-linker" class="scroll" href="#pastfires">Past fires</a></li>
    <li><a id="team-linker" class="scroll" href="#team">Chief fire lighter</a></li>
    <li><a id="portfolio-linker" class="scroll" href="#seriesfires">Series of fires</a></li>
    <li><a id="contact-linker" class="scroll" href="#contact">Get fired up</a></li>
</ul>
</body>
</html>

You will observe:

  1. Right Border is applied to each li
  2. Right Border is removed for last li
  3. I have changed the LINK color to red just for a demo purpose - you may latter remove that.
Pralhad Narsinh Sonar
  • 1,406
  • 1
  • 14
  • 23
0

try this one

li+li { border-left: 1px solid #000000 }

this will affect only adjecent li elements

found here http://www.jackreichert.com/2011/07/31/how-to-add-a-divider-between-menu-items-in-css-using-only-one-selector/

Anil Meenugu
  • 1,411
  • 1
  • 11
  • 16