如何在 WordPress 中将 superfish 菜单居中(在 IE7 中)
我有一个 WordPress 博客,其中的菜单我想设计为 superfish 下拉菜单,我遵循了本教程: http://kav.in/wordpress-superfish-dropdown-menu
到目前为止,菜单看起来很棒,但我需要它居中而不是左对齐。这是我的代码:
#navwrap {
float: left;
width: 100%;
background: url(images/bg.png) repeat transparent;
text-transform: uppercase;
font-size: 12px;
height: 40px;
}
.sf-menu {
float: left;
width: 100%;
text-align:center;
}
.sf-menu li {
background: transparent;
}
.sf-menu a {
padding: 0px 15px;
text-decoration: none;
line-height: 40px;
}
.sf-menu ul li a {
padding: 0px 15px;
text-decoration: none;
}
.sf-menu li li {
background: #611718;
text-align: left;
}
我的菜单中的项目当然具有可变宽度。
我没有没有所有 sf 类的 html,但它是一个简单的列表,或多或少像这样:
<div id="navwrap">
<ul class="sf-menu">
<li><a href="#">List item</a></li>
<li><a href="#">List item</a></li>
<li><a href="#">List item</a></li>
<li><a href="#">List item</a>
<ul>
<li><a href="#">List item</a></li>
<li><a href="#">List item</a></li>
<li><a href="#">List item</a></li>
</ul>
</li>
</ul>
</div>
编辑:我找到了一种将其居中的方法,但它在 IE7 中不起作用。
好吧,我尝试了一种在谷歌上搜索的方法,它似乎有效,直到我检查了 IE7,看起来 inline-block 使菜单完全中断:
#navwrap .sf-menu {
text-align: center;
}
#navwrap .sf-menu li {
display: inline-block;
float: none;
}
#navwrap .sf-menu li a {
display: inline-block;
}
这是我正在处理的页面: http://hermandaddelcalvario.org/wordpress/ 您可以在 IE7 损坏时检查顶部菜单。
I have a wordpress blog with a menu I wanted to style as a superfish dropdown menu and I followed this tutorial: http://kav.in/wordpress-superfish-dropdown-menu
So far the menu looks great but I need it to be centered instead of aligned left. Here is my code:
#navwrap {
float: left;
width: 100%;
background: url(images/bg.png) repeat transparent;
text-transform: uppercase;
font-size: 12px;
height: 40px;
}
.sf-menu {
float: left;
width: 100%;
text-align:center;
}
.sf-menu li {
background: transparent;
}
.sf-menu a {
padding: 0px 15px;
text-decoration: none;
line-height: 40px;
}
.sf-menu ul li a {
padding: 0px 15px;
text-decoration: none;
}
.sf-menu li li {
background: #611718;
text-align: left;
}
The items in my menu have of course variable width.
I don't have the html without all the sf classes but it's a simple list more or less like this:
<div id="navwrap">
<ul class="sf-menu">
<li><a href="#">List item</a></li>
<li><a href="#">List item</a></li>
<li><a href="#">List item</a></li>
<li><a href="#">List item</a>
<ul>
<li><a href="#">List item</a></li>
<li><a href="#">List item</a></li>
<li><a href="#">List item</a></li>
</ul>
</li>
</ul>
</div>
Edit: I found a way to center it but it doesn't work in IE7.
Ok, I tried an approach I found searching on google and it seemed to work until I checked IE7, looks like inline-block is making the menu break completely:
#navwrap .sf-menu {
text-align: center;
}
#navwrap .sf-menu li {
display: inline-block;
float: none;
}
#navwrap .sf-menu li a {
display: inline-block;
}
This is the page I'm working on: http://hermandaddelcalvario.org/wordpress/ You can check the top menu in IE7 as it breaks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IE7 不喜欢对原本是块级元素的元素进行 inline-block。
但是您没有在
li
上使用任何边距,那么为什么不使用display: inline;
呢?我认为这不会有任何区别。看来使用内联会使菜单消失。
删除
float: left;
似乎可以解决这个问题。(无论如何,为什么菜单是浮动的?它似乎没有任何区别。)
IE7 does not like inline-block for elements that are originally block-level elements.
But you are not using any margin on the
li
s, so why not usedisplay: inline;
instead? I think it would not make any difference whatsoever.It seems that using inline makes the menu disappear.
Removing the
float: left;
seems to fix that.(Why is the menu floated, anyway? It does not seem to make any difference.)
你可以尝试这样的事情:
并在 .wrapper 中添加#navwrap。
该列表不会真正居中,但实际上已经尽可能接近了。
You could try something like this:
And have #navwrap inside .wrapper.
The list won't be truly centred, but it's as close as you'll get, really.