Vertical dividers on horizontal UL menu

前端 未结 8 447
情书的邮戳
情书的邮戳 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:58

    Quite and simple without any "having to specify the first element". CSS is more powerful than most think (e.g. the first-child:before is great!). But this is by far the cleanest and most proper way to do this, at least in my opinion it is.

    #navigation ul
    {
        margin: 0;
        padding: 0;
    }
    
    #navigation ul li
    {
        list-style-type: none;
        display: inline;
    }
    
    #navigation li:not(:first-child):before {
        content: " | ";
    }
    

    Now just use a simple unordered list in HTML and it'll populate it for you. HTML should look like this:

    <div id="navigation">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About Us</a></li>
            <li><a href="#">Support</a></li>
        </ul>
    </div><!-- navigation -->
    

    The result will be just like this:

    HOME | ABOUT US | SUPPORT

    Now you can indefinitely expand and never have to worry about order, changing links, or your first entry. It's all automated and works great!

    0 讨论(0)
  • 2020-12-23 10:00

    I do it as Pekka says. Put an inline style on each <li>:

    style="border-right: solid 1px #555; border-left: solid 1px #111;"
    

    Take off first and last as appropriate.

    0 讨论(0)
提交回复
热议问题