Search code examples
csscenteringnav

Centering Navigation ul li


I can't seem to get the main navigation bar to center align the li elements. I'm only having problems when the browser is under 768px. I've tried display: inline-block on the #nav ul and then text align to no avail. Here is the site: Website

and here is the CSS in question:

/* Main Navigation */   
#topmenu {float: left; height: auto; text-align: center; margin: -10px auto -10px 10px; display: block; width: 96%;}
#nav {float: left; border-left: none; margin: 10px auto 0px; text-align: center;  display: block; width: 100%;}
#nav li {float: left; margin-right: auto; border-right: none; width: auto;}
#nav li a:link, #nav li a:active, #nav li a:visited {display: block;text-decoration: none; line-height: 20px; outline: medium none; font-size: 19px; letter-spacing: -0.05em; float: left;    padding: 6px 9px 8px; text-align: center; width: auto;}
span.descmenu {display: none;}

Solution

  • Apply these properties/values

    #nav {
        text-align: center; /*add*/
    }
    #nav li {
        display: inline-block; /*add*/
        text-align: left; /*add*/
        float: none; /*change left to none on max-width: 767px */
    }