[英]Centering Navigation ul li
我似乎无法使主导航栏居中对齐li元素。 当浏览器低于768px时,我才遇到问题。 我试过在#nav ul上进行display:inline-block,然后将文本对齐无济于事。 这是网站: 网站
这是有问题的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;
}
看一下css,它看起来像个float:left或padding / margin可能会覆盖您要样式化的li。
应用这些属性/值
#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 */
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.