html - 不可见的元素在不应该的时候被悬停

标签 html css button navbar dropdown

我为我的导航栏编写了一个下拉登录表单,它工作正常但不完全,当我将鼠标悬停在表单出现的区域时它似乎也会下降:

鼠标只是悬停在出现下拉菜单的区域,但它不应该那样做,当我仅将鼠标悬停在“ingresar”上时它应该会下降,如何解决这个问题?另外,我不希望我的鼠标看起来像是可以点击表单,它应该看起来很正常。

.login-box {
  width: 350px;
  height: 420px;
  padding: 80px 40px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, .8);
  position: absolute;
  right: 0px;
  top: 100%;
  opacity: 0;
}
.menu li:hover .login-box {
  opacity: 1;
}
h2 {
  margin: 0;
  padding: 0 0 10px;
  color: #efed40;
  text-align: center;
}
.login-box p {
  margin: 0;
  padding: 0;
  font-weight: bold;
  color: white;
}
.login-box input {
  width: 100%;
  margin-bottom: 20px;
}
.login-box input[type="text"],
.login-box input[type="password"] {
  border: none;
  border-bottom: 1px solid #fff;
  background: transparent;
  outline: none;
  height: 40px;
  color: #fff;
  font-size: 16px;
}
::placeholder {
  color: rgba(255, 255, 255, .3);
  font-family: sans-serif;
  font-weight: bold;
}
.login-box input[type="submit"] {
  border: none;
  outline: none;
  height: 40px;
  color: #fff;
  font-size: 16px;
  background: #ff267e;
  cursor: pointer;
  border-radius: 20px;
}
.login-box input[type="submit"]:hover {
  background: #efed40;
  color: #262626;
}
.login-box a {
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  text-decoration: none;
}
<ul class="menu">
  <li>INICIO</li>
  <li class="with-arrow">CONTACTO</li>
  <li class="with-arrow">REGISTRATE</li>
  <li class="with-arrow">INGRESAR
    <div class="login-box">
      <h2>Ingresa tus datos</h2>
      <form>
        <p>CORREO</p>
        <input type="text" name="" placeholder="Escribir e-mail">
        <p>CONTRASEÑA</p>
        <input type="password" name="" placeholder="Escribir Contraseña">
        <input type="submit" name="" value="Listo">
        <a href="">¿Contraseña olvidada?</a>
      </form>
    </div>
  </li>
</ul>

最佳答案

您需要将下拉列表设置为不可见,因此不能在其中应用悬停事件

.login-box{
  width: 350px;
  height: 420px;
  padding: 80px 40px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, .8);
  position: absolute;
  right: 0px;
  top: 100%;
  opacity: 0;
  /* === NEW ==== */
  visibility: hidden;
}
.menu li:hover .login-box{
  opacity: 1;
  /* === NEW ==== */
  visibility: visible;
}

visibility

关于html - 不可见的元素在不应该的时候被悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49177902/

相关文章:

html - 如何在 Vue 路由器中定义要在组件内部使用的变量?

javascript - 如何拆分长电子邮件以适合页面上的一列

javascript - 如何创建顺序图像淡入淡出?

html - DIV在IE中的位置不对

php - 如何将 CSS 应用于提交按钮

javascript - 如何暂停/停止计时器?

javascript - Jquery:最近()行删除不起作用

html - 在 css 中使用 div 作为剪贴蒙版

jquery - 在移动 safari 中滚动动画

c# - 如何根据按钮点击设置Label的内容