【问题标题】:Toggle menu is not fully visible on click event切换菜单在点击事件中不完全可见
【发布时间】:2014-09-30 16:11:20
【问题描述】:

当用户单击按钮时,我必须创建带有项目的切换菜单。但该菜单并不完全可见。

在 html 中,我定义了带有菜单的切换按钮:

<div class="button toggle">Toggle on right
    <div class="toggle-menu">
        <a href="#">Link 1</a><br />
        <a href="#">Link 2</a><br />
        <a href="#">Link 3</a>
    </div>
</div>

还有 CSS (SCSS):

.button {
    position: relative;
    display: inline-block;
    padding: 5px 8px;
    margin: 5px 20px;
    background-color: lime;
    border: 1px solid gray;
    border-radius: 3px;
    cursor: pointer;

    &.toggle > .toggle-menu {
        position: absolute;
        top: 32px;
        right: 0;
        background-color: lime;
        border: 1px solid gray;
        width: 100%;
        display: none;
    }
}

这是JSFIDDLE,我的完整代码在哪里。

PS: 这不是我在实时页面上的实际代码。就像例子,但同样的问题。

【问题讨论】:

    标签: jquery html css sass


    【解决方案1】:

    应用 z-index:

    .button {
        position: relative;
        display: inline-block;
        padding: 5px 8px;
        margin: 5px 20px;
        background-color: lime;
        border: 1px solid gray;
        border-radius: 3px;
        cursor: pointer;
    
        &.toggle > .toggle-menu {
            position: absolute;
            top: 32px;
            right: 0;
            background-color: lime;
            border: 1px solid gray;
            width: 100%;
            display: none;
            z-index: 99; /* added here */
        }
    }
    

    【讨论】:

    • 谢谢,这适用于这个例子,但不适用于实时代码(原因:我已经在元素上有 z-indexes),所以我会尽快更新问题。
    • 不,它没有帮助。我会尝试做出更好的复制,我在网站上的实际代码太长,无法在此处或 jsfiddle 发布(idk 那个错误在哪里)。
    • 我会尽可能多地尝试,但我无法向您展示整个代码,这是商业和公司问题。
    • @debute :复制问题或分享您面临问题的代码。根据问题,它得到了回答。
    • 我会尝试自己做,我将所有样式从网站复制到 jsfiddle,仍然只在 jsfiddle 上工作。
    猜你喜欢
    • 1970-01-01
    • 2015-05-04
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    • 2020-06-11
    • 2011-05-24
    • 1970-01-01
    相关资源
    最近更新 更多