【问题标题】:CSS Submenu Align Center in WordpressWordPress中的CSS子菜单对齐中心
【发布时间】:2012-03-06 09:55:21
【问题描述】:

您好,我必须使用 wordpress 为网站创建一个水平子菜单。我玩了 CSS 并且快到了,我只需要将子菜单中的链接对齐到中心。我试过了:

text-align: center;

在#access ul ul 中,但这似乎不起作用:S

网站是:http://dev.timson.me(“即将上映”和“过往作品”的子菜单)

CSS 是:

#access {
clear: both;
display: block;
float: left;
margin: 0 auto 6px;
padding-top: 8px;
width: 100%;
font-family: Stag;
display:block;
text-align:center;
}

#access ul {
    font-size: 13px;
    list-style: none;
    margin: 0 0 0 -0.8125em;
    padding-left: 0;

    display:inline-block;
}
#access li {
    float: left;
    position: relative;
}

#access a {
    color: #eee;
    display: block;
    line-height: 25px;
    margin-top: -4px;
    margin-bottom: -4px;
    padding: 0 1.2125em;
    text-decoration: none;
}

#access ul ul {

    display: none;
    float: left;
    margin-top: 0;
    position: fixed;
    top: 264px;
    left: 50%;
    width: 1000px;
    z-index: 99999;
    margin-left:-500px;
    text-align:center;
    padding-top:5px;
    padding-bottom:10px;

    background: red;
}

#access ul ul a {

    margin-top: 0px;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    padding-bottom:10px;

}

#access ul li:hover > ul {
    display: block;
}

任何帮助都非常感谢欢呼。

彼得

【问题讨论】:

    标签: css wordpress html-lists center submenu


    【解决方案1】:

    首先,添加这条规则

    .sub-menu {
        text-align: center;
    }
    

    第二,改变

    #access li {
        float: left;
        position: relative;
    }
    

    #menu-default > li {
        float: left;
        position: relative;
    }
    

    第三,添加这条规则

    .sub-menu > li {
        display: inline-block;
    }
    

    【讨论】:

    • 非常感谢您!我刚刚发现我需要修复的另一件事,如果您向下滚动然后尝试使用菜单,子菜单会出现在页面的中间,因为:位置:固定;顶部:264 像素;你知道如何解决这个问题
    • 嗯,无法复制那个。在我测试过的几个浏览器中,子菜单出现在正确的位置。
    猜你喜欢
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多