使用CSS的嵌套下拉菜单

时间:2019-07-18 07:45:16

标签: html css

尝试使用简单的CSS嵌套下拉菜单。我正在尝试制作导航菜单。除了当我将鼠标悬停在“新此处”下的“关于我们”部分时,所有内容似乎都工作正常,它向我显示了正确的结果。但问题是,当我将鼠标悬停在其下一节时,它不会消失。我该如何解决?这是The Link For the 片段供您考虑,请告诉我我在哪里做错了。 这是供您查看的代码。

   .dropbtn2
  {
    position: relative;
    display: none;
  }
  .dropdown {
    position: relative;
    display: inline-block;
  }

  /* Dropdown Content (Hidden by Default) */
  .dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 169px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
  }

  /* Links inside the dropdown */
  .dropdown-content a {
    color: black;
    font-size:20px;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
  }

  /* Change color of dropdown links on hover */
  .dropdown-content a:hover {background-color: #f1f1f1}

  /* Show the dropdown menu on hover */
  .dropdown:hover .dropdown-content {
    display: block;
    transition:none;
  }
  .dropdown-content a:hover {
    padding-top:15px;
    transition:ease-in-out .5s;
  }
  .dropdown:hover .dropbtn
  {
    background-color: #8300ff;
    color: #182318;
    padding-top: 500px;
    padding-bottom: 30px;
    padding-right: 20px;
    padding-left: 20px;
    transition: ease-out 0.5s;
    text-decoration: none;
    box-shadow:none;

  }
  /* End*/
  .dropdown-content2 {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width:170px;
    left:170px;
    top:0;
    z-index: 1;
  }

  /* Links inside the dropdown */
  .dropdown-content2 a {
    color: black;
    font-size:20px;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
  }

  /* Change color of dropdown links on hover */
  .dropdown-content2 a:hover {background-color: #f1f1f1}

  /* Show the dropdown menu on hover */
  .dropdown-content:hover .dropdown-content2 {
    display: block;
    transition:none;
  }
  .dropdown-content2 a:hover {
    padding-top:15px;
    transition:ease-in-out .5s;
  }
  .dropdown a:hover .dropbtn2
  {
    padding-bottom: 30px;
    padding-right: 20px;
    padding-left: 20px;
    transition: ease-out 0.5s;
    text-decoration: none;
    box-shadow:none;

  }

  /*TEST*/

1 个答案:

答案 0 :(得分:0)

您需要将元素更改为悬停,以便仅在悬停第一个链接时显示dropdown-content

要替换的值在代码笔的第182行。将dropdown-content:hover .dropdown-content2替换为.dropdown2:hover .dropdown-content2

第181-185行:

  /* Show the dropdown menu on hover */
  .dropdown2:hover .dropdown-content2 { /* change the hover element here */
    display: block;
    transition:none;
  }