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 */
}
Question
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 2
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 */
}
OTHER TIPS
The display:inline-block
and text-align: center
technique does work here, but you need to make sure that on the smaller screen your ul (#nav
) is not floated and doesn't have a width set.
@media screen and (max-width: 767px) {
#nav {
float: none; /* Changed from float: left*/
border-left: none;
margin: 10px auto 0px;
/* text-align: center; NOT NEEDED */
display: inline-block; /* Changed from display: block */
/*width: 100%; Remove */
}
}
This will center the sub heading in the navbar
#nav {
text-align: center;
}
Having a look at the css it looks like a float:left or padding/margin might be overiding the li your wanting to style.