Css 对中导航ulli
我似乎无法让主导航栏将li元素居中对齐。我只有在浏览器低于768px时才会出现问题。我试过在#nav ul上显示:内联块,然后文本对齐,但没有效果。以下是网站: 下面是有问题的CSS:Css 对中导航ulli,css,centering,nav,Css,Centering,Nav,我似乎无法让主导航栏将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: l
/* 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;
}
看一看css,它看起来像一个浮点:左边或边距/边距可能超出了您想要的样式。应用这些属性/值
#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 */
}
工作得很好。我把事情弄得太复杂了。谢谢你的帮助大卫。我确实删除了那些不必要的行。