3

I have a HTML ul li like this:

<ul id="menu-footer-menu" class="menu">
   <li id="menu-item-356" class="menu-item menu-item-type-taxonomy menu-item-356">
      <a href="http://example.com/link1/">Title 1</a>
      <span class="f_sep">|</span>
   </li>
   <li id="menu-item-357" class="menu-item menu-item-type-taxonomy menu-item-357">
      <a href="http://example.com/link2/">Title 2</a>
      <span class="f_sep">|</span>
   </li>
   <li id="menu-item-358" class="menu-item menu-item-type-taxonomy menu-item-358">
      <a href="http://example.com/link3/">Title 3</a>
      <span class="f_sep">|</span>
   </li>
</ul>

which output like this

Title 1 | Title 2 | Title 3 | 

So throught CSS I want to hide last |. I tried this but it is hidding all the |

#menu-footer-menu .f_sep:last-child{display:none}

I want the final output like this

Title 1 | Title 2 | Title 3  

Please Note: my question is not related to this question because there it is been adding | through, but I already has pipe | in my HTML so I just want to hide the last occurrence.

Community
  • 1
  • 1
Promit
  • 120
  • 1
  • 2
  • 10
  • Possible duplicate of [Add a pipe separator after items in an unordered list unless that item is the last on a line](http://stackoverflow.com/questions/9171699/add-a-pipe-separator-after-items-in-an-unordered-list-unless-that-item-is-the-la) – marmeladze Mar 14 '17 at 05:30
  • #menu-footer-menu li:last-child – Alfin Paul Mar 14 '17 at 05:30
  • @marmeladze: please read my _Please Note_ section. Hope it make sense. – Promit Mar 14 '17 at 07:02

6 Answers6

6

You are doing it wrong. Here is the correct answer:

#menu-footer-menu li:last-child .f_sep{ display:none }
Simrandeep Singh
  • 569
  • 3
  • 15
2
#menu-footer-menu li:last-child .f_sep{
  display: none;
}
Alfin Paul
  • 1,543
  • 14
  • 26
2

Use this CSS

#menu-footer-menu li:last-child .f_sep{display:none}
1

You can try this:

ul li:last-child span {
  display: none;
}
Mers
  • 736
  • 4
  • 12
1

Better still use more semantic markup and display the divider with css

#menu-footer-menu{list-style:none; padding:0;}

#menu-footer-menu li {display:inline-block;}

#menu-footer-menu li:not(:last-child):after
{
  content: "|";  
}
<ul id="menu-footer-menu" class="menu">
   <li id="menu-item-356" class="menu-item menu-item-type-taxonomy menu-item-356">
      <a href="http://example.com/link1/">Title 1</a>
   </li>
   <li id="menu-item-357" class="menu-item menu-item-type-taxonomy menu-item-357">
      <a href="http://example.com/link2/">Title 2</a>
   </li>
   <li id="menu-item-358" class="menu-item menu-item-type-taxonomy menu-item-358">
      <a href="http://example.com/link3/">Title 3</a>
   </li>
</ul>

The advantage of this, is you can just change the divider with CSS

Jon P
  • 19,442
  • 8
  • 49
  • 72
  • I cannot do this because plugin is generating this code, So I have to remove it through CSS only; but thanks for your help. I'll use this approach if I have to make the `ul li` by myself. – Promit Mar 14 '17 at 07:11
-1

You are close to it. Just go with Li elements.

li:last-child span{
  display:none;
  }
<ul id="menu-footer-menu" class="menu">
   <li id="menu-item-356" class="menu-item menu-item-type-taxonomy menu-item-356">
      <a href="http://example.com/link1/">Title 1</a>
      <span class="f_sep">|</span>
   </li>
   <li id="menu-item-357" class="menu-item menu-item-type-taxonomy menu-item-357">
      <a href="http://example.com/link2/">Title 2</a>
      <span class="f_sep">|</span>
   </li>
   <li id="menu-item-358" class="menu-item menu-item-type-taxonomy menu-item-358">
      <a href="http://example.com/link3/">Title 3</a>
      <span class="f_sep">|</span>
   </li>
</ul>
Shivkumar kondi
  • 6,458
  • 9
  • 31
  • 58