Float items in a taskbar right+left when they are all in a <li> tag

Viewed 30

My navbar looks like this: https://ibb.co/rs7Ndr5

I want to add another link to my navbar, "register", which would appear on the far right side. The only thing is, I made the navbar that there is a

  • with all of the links, and everything in that list is put in the navbar using css. So if I added the new item into the list, it would be floated left like everything else in the list, because the css puts everything in a
  • tag into the navbar.

    This is my css:

    <style>
    ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: Tahoma, Geneva, sans-serif;
    background-color: #333;
    }
    li {
    float: left;
    border-right: 1px solid #bbb;
    }
    li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    }
    /* Change the link color to #111 (black) on hover */
    li a:hover {
    background-color: #111;
    }
    /* for buttons*/
    .paging {
    background-color: #333;
    border: none;
    color: white;
    padding: 8px 14px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    font-family: Tahoma, Geneva, sans-serif;
    }
    button:hover {
    background-color: #111;
    }
    </style>
    

    This is the html:

    <ul>
    <li class="all"><a href="/">All videos</a></li>
    <li class="stam"><a href="/stam">Stam videos</a></li>
    <li class="music"><a href="/music">Music videos</a></li>
    <li class="news"><a href="/news">News videos</a></li>
    <li class="news"><a href="/contact">Contact</a></li>
    </ul>
    

    Please help me! Thanks so much!

  • 1 Answers

    I think I understand what you want to achieve. You can add a class to the new "register" button and float it to the right. Like this:

    ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: Tahoma, Geneva, sans-serif;
    background-color: #333;
    }
    li {
    float: left;
    border-right: 1px solid #bbb;
    }
    li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    }
    /* Change the link color to #111 (black) on hover */
    li a:hover {
    background-color: #111;
    }
    /* for buttons*/
    .paging {
    background-color: #333;
    border: none;
    color: white;
    padding: 8px 14px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    font-family: Tahoma, Geneva, sans-serif;
    }
    button:hover {
    background-color: #111;
    }
    
    .register {
      float: right;
    }
    <ul>
    <li class="all"><a href="/">All videos</a></li>
    <li class="stam"><a href="/stam">Stam videos</a></li>
    <li class="music"><a href="/music">Music videos</a></li>
    <li class="news"><a href="/news">News videos</a></li>
    <li class="news"><a href="/contact">Contact</a></li>
    <li class="register"><a href="/contact">Register</a></li>
    </ul>

    Related