如何在下拉菜单的<a href="#">链接3 </a>中添加子下拉菜单?

时间:2019-11-17 01:42:23

标签: html css

这是下面的代码,我在下拉菜单中添加链接3时遇到问题,好像每次添加此链接都不接受它会创建一个未关联的新的特定子列表。试图在网上找到更多信息,但没有具体内容,有什么想法吗?尝试将下拉子菜单应用于代码。

     --

  1.   

    列表项

=======

body {
  font-family: Arial, Helvetica, sans-serif;
}

.navbar {
  overflow: hidden;
  background-color: #333;
}

.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.dropdown {
  float: right;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 16px;
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.navbar a:hover,
.dropdown:hover .dropbtn {
  background-color: red;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.dropdown-content a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.dropdown-content a:hover {
  background-color: #ddd;
}

.dropdown:hover .dropdown-content {
  display: block;
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" type="text/css" href="style_layout.css">
  <title>Travel Agency</title>
</head>

<body>

  <header>
    <div class="navbar">
      <a href="#home">
        <a class="active" href="#home"><img src="images/logo.jpg" width="100px"></a>
        <div class="dropdown">
          <button class="dropbtn">Dropdown 
      <i class="fa fa-caret-down"></i>
    </button>
          <div class="dropdown-content">
            <a href="#">Link 1</a>
            <a href="#">Link 2</a>
            <a href="#">Link 3</a>
            <a href="#">Link 4</a>
            <a href="#">Link 5</a>
          </div>
        </div>
    </div>
  </header>

</body>

</html>

1 个答案:

答案 0 :(得分:0)

好的,尝试了一下,但这不是最干净的方法

Img