【问题标题】:<li> tags are getting stacked while using mmenu<li> 标签在使用 mmenu 时被堆叠
【发布时间】:2016-04-06 13:07:35
【问题描述】:

我正在使用mmenu jquery library 在我的网站上制作移动菜单。我在我的网站中复制粘贴的确切实现代码,并且 mmenu 正在工作,但菜单中的 &lt;li&gt; 行相互堆叠。我相信 mmenu &lt;nav&gt; 的 css 规则从容器 div 中继承了一些 css 规则。当我尝试使用 mmenu 网站上提到的基本示例时,菜单内的这种堆叠行甚至发生了(我的实现提前)。

请帮我解决这个问题。

实际的菜单示例可以找到here

我的实现截图:

<nav id="menu">
    <ul>
        <li>
            <a href="#/">
                <i class="fa fa-home"></i> 
                Home
                </a>
        </li>
        <li>
            <a href="#/about">
                <i class="fa fa-user"></i> 
                About us
            </a>
        </li>
        <li>
            <a href="#/contact">
                <i class="fa fa-envelope"></i> 
                Contact
            </a>
        </li>
    </ul>
</nav>
jQuery(document).ready(function($) {
    $("#menu").mmenu({
        extensions: [ 
            "theme-black", 
            "effect-menu-zoom", 
            "effect-panels-zoom", 
            "pagedim-black" 
        ],
        navbar: false,
        navbars: {
            height: 4,
            content: [ 
                '<a href="#/" class="fa fa-phone"></a>',
                '<img src="http://lorempixel.com/60/60/people/1/" />',
                '<a href="#/" class="fa fa-envelope"></a>'
            ]
        }
    }).on('click', 'a[href^="#/"]', function() {
        alert("Clicked");
        return false;
    });
});
.mm-menu {
    background: #440011 !important;
}
.mm-navbar {
    text-align: center;
    position: relative;
    border-bottom: none;
}
.mm-navbar:before {
    content: "";
    display: inline-block;
    vertical-align: middle;
    height: 100%;
    width: 1px;
}
.mm-navbar > * {
    display: inline-block;
    vertical-align: middle;
}
.mm-navbar img {
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 60px;
    width: 60px;
    height: 60px;
    padding: 10px;
    margin: 0 10px;
}
.mm-navbar a {
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 40px;
    color: rgba(255, 255, 255, 0.6) !important;
    font-size: 16px !important;
    line-height: 40px;
    width: 40px;
    height: 40px;
    padding: 0;
}
.mm-navbar a:hover {
    border-color: #fff;
    color: #fff !important;
}
.mm-listview {
    text-transform: uppercase;
    font-size: 12px;
}
.mm-listview li:last-child:after {
    content: none;
    display: none;
}
.mm-listview li:after {
    left: 20px !important;
    right: 20px !important;
}
.mm-listview a {
    text-align: center;
    padding: 30px 0 !important;
}
.mm-listview a,
.mm-listview .fa {
    color: rgba(255, 255, 255, 0.6);
}
.mm-listview a:hover,
.mm-listview a:hover .fa {
    color: #fff;
}
.mm-listview .fa {
    position: absolute;
    left: 20px;
}

html.mm-opened.mm-effect-zoom-menu body
{
    background: #f3f3f3;
}
html.mm-opened.mm-effect-zoom-menu.mm-theme-dark body
{
     background: #333;
}
html.mm-opened.mm-effect-zoom-menu.mm-theme-black body
{
    background: #000;
}
html.mm-opened.mm-effect-zoom-menu.mm-theme-white body
{
    background: #fff;
}
html.mm-opened.mm-effect-zoom-menu .mm-page
{
    background-color: #fff;
}

.mm-menu li .fa
{
    margin: 0 20px 0 5px;
    font-size: 16px;
    width: 12px;
}
.mm-menu li[class*="mm-tile"] .fa
{
    margin: 0;
    line-height: 0;
}

.mm-menu .buttonbar-item:after
{
    content: none !important;
    display: none !important;
}

修改 删除position:absolute 后,按照答案的指导,我在单行中得到&lt;li&gt;

【问题讨论】:

    标签: javascript jquery html css mmenu


    【解决方案1】:

    你给你的链接fa 类,然后绝对定位它们。容器没有相对定位,所以他们只是从屏幕上读取。

            .mm-listview .fa {
                position: absolute;
                left: 20px;
            }
    

    【讨论】:

    • 如果我从这个 css 规则中删除 postion:absolute ,那么它们会变得可见但只在单行中。我需要它们中的每一个在不同的行中
    • 然后确保正确放置容器。即.mm-listview {position: relative; }
    • 我添加了 .mm-listview {position: relative;并保持 .fa 链接与 position:absolute 一样,但仍然没有得到想要的结果
    • 请提供一个 jsfiddle,这样我就可以准确了解您想要实现的目标以及您的问题所在。根据您发布的内容,您的 HTML 代码中缺少您引用的大多数类 - 所以我无法真正看到您的版本中发生了什么。
    • 我试图给出一个 jsfiddle 的例子,但是有很多脚本和样式表被引用,我正在用更多的 css 编辑答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 1970-01-01
    相关资源
    最近更新 更多