1

我使用Magento 的自定义菜单扩展,但不知道如何更改 custommenu.css 以使菜单居中。这是一段菜单代码:

<div class="nav-container">
  <div id="custommenu">
    <div id="menu3" class="menu" onmouseout="wpHideMenuPopup(this, event, 'popup3', 'menu3')" onmouseover="wpShowMenuPopup(this, 'popup3');">
    <div id="popup3" class="wp-custom-menu-popup" onmouseover="wpPopupOver(this, event, 'popup3', 'menu3')" onmouseout="wpHideMenuPopup(this, event, 'popup3', 'menu3')" style="z-index: 9999;">
    <div id="menu4" class="menu" onmouseout="wpHideMenuPopup(this, event, 'popup4', 'menu4')" onmouseover="wpShowMenuPopup(this, 'popup4');">
    <div id="popup4" class="wp-custom-menu-popup" onmouseover="wpPopupOver(this, event, 'popup4', 'menu4')" onmouseout="wpHideMenuPopup(this, event, 'popup4', 'menu4')" style="display: none; top: 25px; left: 77px; z-index: 10000;">
... rest of code...

这就是我在 CSS 中尝试的方法 - text-align for #custommenu + display:inline-block for div.menu (以及其他一些选项)但无法正常工作:

#custommenu {
    position:relative;
    font-size: 14px;
    margin: 0 auto;
    padding: 0 16px;
    width: 918px;
    z-index: 999;
    text-align: center;    
}
div.menu {
    display:inline-block;
    float: left;
}

你能给我一些提示如何让菜单居中吗?我在这里做错了什么?

4

1 回答 1

0

我不确定这是否会解决您的 CSS 问题,但您的<div>s 未关闭:

更正的 HTML:

<div class="nav-container">
<div id="custommenu">
    <div id="menu3" class="menu" onmouseout="wpHideMenuPopup(this, event, 'popup3', 'menu3')" onmouseover="wpShowMenuPopup(this, 'popup3');"></div>
    <div id="popup3" class="wp-custom-menu-popup" onmouseover="wpPopupOver(this, event, 'popup3', 'menu3')" onmouseout="wpHideMenuPopup(this, event, 'popup3', 'menu3')" style="z-index: 9999;"></div>
    <div id="menu4" class="menu" onmouseout="wpHideMenuPopup(this, event, 'popup4', 'menu4')" onmouseover="wpShowMenuPopup(this, 'popup4');"></div>
    <div id="popup4" class="wp-custom-menu-popup" onmouseover="wpPopupOver(this, event, 'popup4', 'menu4')" onmouseout="wpHideMenuPopup(this, event, 'popup4', 'menu4')" style="display: none; top: 25px; left: 77px; z-index: 10000;"></div>
</div>
</div>

如果您无权访问 CSS 文件来编辑它,您可以尝试将其包装<div class="nav-container">在另一个<div>.

例子:

<div class="nav-wrapper">
    <div class="nav-container">
        <div id="custommenu">
            ...
        </div>
    </div>
</div>

然后像这样引用CSS:

div.nav-wrapper div.nav-container div#custommenu {
    position:relative;
    font-size: 14px;
    margin: 0 auto;
    padding: 0 16px;
    width: 918px;
    z-index: 999;
    text-align: center;    
}
div.nav-wrapper div.nav-container div#custommenu div.menu {
    display:inline-block;
    float: left;
}
于 2013-01-16T15:11:48.760 回答