Vertical dividers on horizontal UL menu

前端 未结 8 446
情书的邮戳
情书的邮戳 2020-12-23 09:30

I\'m trying to create a horizontal navigation bar (no dropdown, just a horizontal list), but I\'m having trouble finding the best way to add vertical dividers between the me

相关标签:
8条回答
  • 2020-12-23 09:43
    .last { border-right: none
    
    .last { border-right: none !important; }
    
    0 讨论(0)
  • 2020-12-23 09:44

    I think your best shot is a border-left property that is assigned to each one of the lis except the first one (You would have to give the first one a class named first and explicitly remove the border for that).

    Even if you are generating the <li> programmatically, assigning a first class should be easy.

    0 讨论(0)
  • 2020-12-23 09:46

    A simpler solution would be to just add #navigation ul li~li { border-left: 1px solid #857D7A; }

    0 讨论(0)
  • 2020-12-23 09:47

    This can also be done via CSS:pseudo-classes. Support isn't quite as wide and the answer above gives you the same result, but it's pure CSS-y =)

    .ULHMenu li { border-left: solid 2px black; }
    .ULHMenu li:first-child { border: 0px; }
    

    OR:

    .ULHMenu li { border-right: solid 2px black; }
    .ULHMenu li:last-child { border: 0px; }
    

    See: http://www.quirksmode.org/css/firstchild.html
    Or: http://www.w3schools.com/cssref/sel_firstchild.asp

    0 讨论(0)
  • 2020-12-23 09:49

    try this one, seeker:

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

    this will affect only adjecent li elements

    found here

    0 讨论(0)
  • 2020-12-23 09:49

    This works fine for me:

    NB I'm using BEM/OCSS SCSS Syntax

    #navigation{
      li{
         &:after{
            content: '|'; // use content for box-sizing
            text-indent: -999999px; // Hide the content
            display: block;
            float: right; // Position
            width: 1px;
            height: 100%; // The 100% of parent (li)
            background: black; // The color
            margin: {
              left: 5px;
              right: 5px;
            }
          }
    
          &:last-child{
    
            &:after{
              content: none;
            }
    
          }
      }
    }
    
    0 讨论(0)
提交回复
热议问题