带子菜单的下拉菜单

Drop Down Menu with Sub Menu

我正在做一个项目,但我正在为一件事情而苦苦挣扎。这可能非常简单,但我显然看多了一些东西。我的 objective 是让菜单和子菜单在悬停在特定图像上时填充。当您将鼠标悬停在图片上时,您会看到 "categories" 并在右侧看到该类别的 "sub-menu"。我能够让第一个类别工作,但无法让任何后续类别将 "sub-menu" 更改为右侧。我已经包含了下面的代码。任何帮助将不胜感激 - 我正在努力完成这项工作

菜单示例:

这是我的造型css:

/* Dropdown Button */
.dropbtn {
    border: none;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
    position: relative;
    display: inline-block;
    z-index: 1;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
    display: none;
    float: right;
    position: absolute;
    background-image: url(../images/Framework-and-Navigation_03.png);
    min-width: 100px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown-content2{
display: block;
    position: relative;
    z-index: 1;
        color: black;
    padding: 12px 16px;
    text-decoration: none;
}
.dropdown-content3{
display: block;
    position: relative;
    z-index: 1;
        color: black;
    padding: 12px 16px;
    text-decoration: none;

}
/* Links inside the dropdown */
.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}
.dropdown-content-sub1 {
    color: black;
    text-decoration: none;
    display: none;
    z-index: 1;
}

.dropdown-content-sub2 {
    color: black;
    text-decoration: none;
    display: none;
}

.dropdown-content-sub3 {
    color: black;
    text-decoration: none;
    display: none;
}



/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: inline-block;}

/* Change the sub menu */
.dropdown-content1:hover .dropdown-content-sub1 {display: block;}

.dropdown-content2:hover .dropdown-content-sub2 {display: inline-block;}

这是我的 menu/submenu 测试:

<div class="dropdown">
      <center>
        <input type="image" class="dropbtn" src="images/menu_07.png"/>
      </center>
<div class="dropdown-content">
<table width="500" border="0" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <td width="158">    
         <div class="dropdown-content1"><a href="">Link 1</a></div>
         <div><a href="#">Link 2</a></div>
         <div><a href="#">Link 3</a></div>   
      </td>
      <td class="dropdown-content-sub1" valign="top"><div>
         <a href="#">Test</a>
         </div>
      </td>
    </tr>
  </tbody>
</table>
</div>
</div>

看看这是否能解决您的问题:)

/* Dropdown Button */
html,
body {
  font-family: arial;
  padding: 0;
  margin: 0;
}

a {
  padding: 10px;
  text-decoration: none;
  display: block;
}

.menu-container {
  width: 615px;
  height: 200px;
  background: #eee url("https://images.unsplash.com/photo-1538098269808-2ace9a4d9680?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=2a48defb8057de5b3f79b49b85c173bc&auto=format&fit=crop&w=500&q=60") no-repeat 200px 0;
  display: none;
  position: absolute;
  top: 50px;
  left: 0;
  box-shadow: 0 0 8px 8px rgba(0, 0, 0, 0.3);
}

ul.menu,
ul.menu ul {
  width: 200px;
  padding: 0;
  margin: 0;
  display: none;
  flex-direction: column;
}
ul.menu li,
ul.menu ul li {
  background: rgba(0, 0, 0, 0.5);
  height: 30px;
  display: flex;
  align-items: center;
}
ul.menu li a,
ul.menu ul li a {
  color: white;
  margin-bottom: 1px;
}
ul.menu li:hover ul,
ul.menu ul li:hover ul {
  display: flex;
}

ul.menu ul {
  position: absolute;
  margin: 0 0 0 200px;
  top: 0;
  z-index: 2;
}

/* The container <div> - needed to position the dropdown content */
.nav {
  background-color: black;
  display: flex;
  flex-direction: row;
}
.nav > .nav-item {
  height: 30px;
  padding: 10px;
  margin-right: 2px;
  background-color: rgba(255, 255, 255, 0.4);
  color: white;
  display: flex;
  align-items: center;
}
.nav > .nav-item:hover > .menu-container,
.nav > .nav-item:hover > .menu-container > .menu {
  display: flex;
}
<div class="nav">
  <div class="nav-item" href="">Nav item 1
    <div class="menu-container">
      <ul class="menu">
        <li><a href="">Menu item 1 ></a>
         <ul>
          <li><a href="">Sub menu 1 item 1</a></li>
          <li><a href="">Sub menu 2 item 2</a></li>
        </ul>
          </li>
        <li><a href="">Menu item 2</a></li>
        <li><a href="">Menu item 3 ></a>
        <ul>
          <li><a href="">Sub menu 2 item 1</a></li>
          <li><a href="">Sub menu 2 item 2</a></li>
        </ul>
          </li>
      </ul>
    </div>
  </div>
  <div class="nav-item" href="">Nav item 2</div>
</div>