我似乎无法获得主导航栏以对齐LI元素。当浏览器不到768px时,我只有问题。我尝试了显示:#nav ul上的内联块,然后文本对齐至无用。这是网站:网站
这是有问题的CSS:
/* 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;}
display:inline-block
和text-align: center
技术确实可以在这里工作,但是您需要确保在较小的屏幕上您的UL(#nav
)没有漂浮并且没有宽度集。
@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 */
}
}
应用这些属性/值
#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 */
}
这将集中在Navbar中的子标题
#nav {
text-align: center;
}
看一下CSS,看起来像浮子:左或填充/边距可能正在超过您想要的样式。