【问题标题】:Dropdown menu closes when I hover the options in Firefox当我将鼠标悬停在 Firefox 中时,下拉菜单关闭
【发布时间】:2016-04-04 03:41:06
【问题描述】:

我使用 Jade 和 CSS 作为下拉菜单

这是玉:

    .dropdown
        button.dropbtn(type="button") Me
          .dropdown-content
            a(href="/favorites") 
              | Favorites
            a(href="/update") 
              | Edit
            a(href="/logout")
              | Logout

这里是css:

.dropdown{
  position: relative;
    display: inline-block;
}
.dropdown-content a{
  display: block;
  padding: 8px 0px;
  text-align: justify;
  color: grey;
  text-decoration: none;
}
.dropbtn {
    background: none;
    color: grey;
    font-size: 16px;
    border: none;
    cursor: pointer;
}
.dropbtn:hover {
  transition: all .2s ease-in-out;
    background: none;
    color: white;
    font-size: 16px;
    border: none;
    cursor: pointer;
}
.dropdown-content{
  display: none;
  position: absolute;
}

.dropbtn:hover .dropdown-content{
  display: block;
}

这基本上使得当您将鼠标悬停在“我”按钮上时 出现下拉按钮,但是当我向下移动光标以选择一个时 它们(编辑:它们表示悬停时出现的下拉菜单选项)立即消失。

似乎这在 Firefox 中不起作用,但在 Chrome 中起作用。

编辑: 原来我需要把玉改成以下(感谢凯昊的帮助):

      .dropdown
        .dropbtn
          | Me
          .dropdown-content
            a(href='/favorites')
              | Favorites
            a(href='/update')
              | Edit
            a(href='/logout') 
              | Logout

【问题讨论】:

    标签: css pug dropdown


    【解决方案1】:

    他们是什么意思?在我的电脑上它确实有效。

    尝试将下拉菜单的position: absolute 更改为relative。也许它不会起作用,因为.dropbtn 高度只会自己拉伸,所以当您将光标悬停时,您不再指向它。 .dropdown-content 中的 position: absolute 不会使其拉伸父内容。不过需要进行一些额外的 CSS 调整。

    .dropdown-content{
        display: none;
        position: relative; /* here */
    }
    

    .dropdown{
      position: relative;
        display: inline-block;
    }
    .dropdown-content a{
      display: block;
      padding: 8px 0px;
      text-align: justify;
      color: grey;
      text-decoration: none;
    }
    .dropbtn {
        background: none;
        color: grey;
        font-size: 16px;
        border: none;
        cursor: pointer;
    }
    .dropbtn:hover {
      transition: all .2s ease-in-out;
        background: none;
        color: white;
        font-size: 16px;
        border: none;
        cursor: pointer;
    }
    .dropdown-content{
      display: none;
      position: relative;
    }
    
    .dropbtn:hover .dropdown-content{
      display: block;
    }
    <div class="dropdown">
      <div class="dropbtn">Me
        <div class="dropdown-content"><a href="/favorites">
             
            Favorites</a><a href="/update">
             
            Edit</a><a href="/logout">Logout</a></div>
      </div>
    </div>

    【讨论】:

    • 这允许我将鼠标悬停在下拉选项上但是,除了对齐关闭之外,我实际上无法单击任何内容,它只是选择了整个 .dropbtn div(即使在更改 z-indexes 之后)
    • 您使用的是什么浏览器/操作系统?
    • ubuntu 上的 firefox 刚刚测试了 chrome 并且它可以工作,但我想这只是让它成为一个新问题。我会在主帖中更新它
    • 尝试将您的 button 更改为 a
    • 还是有同样的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 2018-08-15
    • 2013-07-16
    • 1970-01-01
    • 2013-03-14
    相关资源
    最近更新 更多