简体   繁体   English

如何使水平导航菜单中心对齐

[英]How can i make the horizontal navigation menu center aligned

I am creating a Wordpress theme based on the Twenty Eleven theme and can't figure out how to have the navigation bar center automatically so I won't have to constantly update it. 我正在基于“二十一”主题创建一个Wordpress主题,并且无法弄清楚如何自动使导航栏居中,因此我不必不断对其进行更新。

Here is my CSS: http://pastebin.com/SGvKmXEb 这是我的CSS: http : //pastebin.com/SGvKmXEb

Here is the PHP/HTML: http://pastebin.com/TBL1nzjV 这是PHP / HTML: http : //pastebin.com/TBL1nzjV

There may be duplicate properties in the CSS, but only because I am still experimenting with this and testing multiple things... CSS中可能有重复的属性,但这仅是因为我仍在对此进行试验并测试多件事...

Thanks in advance for the help! 先谢谢您的帮助!

I'd choose an inline-block approach. 我会选择内联块方法。

.containerElement {
    width: 100%;
    text-align: center;
}

.childElements {
    display: inline-block;
}

In order to make it work in your code, you need to remove .containerElement (#access ul) fixed height, and .childElements (#access li) floating property. 为了使其在您的代码中起作用,您需要删除.containerElement (#access ul)固定高度和.childElements (#access li)浮动属性。

This Worked for me on the test site you provided 在您提供的测试网站上,这对我有用

#access li {

float: left; /*delete*/
display:block; /*delete*/

display:inline-block; /*add*/

}

#access ul {

margin-left: 25%; /*delete*/
margin-right: 25%; /*delete*/
width: 1000px; /*delete*/
height: 10px; /*delete*/

margin-bottom: 0px; /*add*/
margin-left: 0px; /*add*/
padding: 0px; /*add*/

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM