导航栏中的下拉列表未显示元素列表(角度6)

时间:2018-09-08 17:51:59

标签: html css angular

我在Angular 6应用中编写了导航栏组件。

<div class="navbar">
<ul>
  <li><a href="default.asp">tekst</a></li>
  <li><a href="news.asp">tekst</a></li>
  <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>
    </div>
  </div>
</ul>
</div>

和.css文件:

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #e8d625;
  position: fixed;
  top: 0;
  width: 100%
}

li {
  float: left;
}

li a {
  display: block;
  color: #090909;
  text-align: center;
  font-weight: bold;
  padding: 14px 16px;
  text-decoration: none;
}

/* Change the link color to #111 (black) on hover */
li a:hover {
  background-color: #f7e525;
}

.active {
  background-color: #f7e525;
}

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

.dropdown .dropbtn {
  font-size: 16px;
  border: none;
  outline: none;
  color: #77ffb7;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit; /* Important for vertical align on mobile phones */
  margin: 0; /* Important for vertical align on mobile phones */
}

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

/* Dropdown content (hidden by default) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #80f987;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

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

/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
  background-color: #80f987;
}

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

但是它不起作用。 当我使用鼠标时,下拉菜单不会显示任何内容。很难说,但是我使用https://www.w3schools.com/css/css_dropdowns.asp。 我没有图书馆吗?

还有其他问题。我以后可以使用下拉菜单吗?因为我使用了RoutingModule。

非常感谢您提供所有答案。

编辑: 添加左侧导航栏

<ul>
  <li><a href="default.asp">Calendar</a></li>
  <li><a href="news.asp">info1</a></li>
  <li><a href="contact.asp">info2</a></li>
  <li><a href="contact.asp">info3</a></li>
  <li><a href="contact.asp">info4</a></li>
</ul>

ul {
  list-style-type: none;
  margin-top: 45px;
  padding: 0;
  width: 200px;
  background-color: #f1f1f1;
  height: 100%;
  position: fixed;
}

li a {
  display: block;
  color: #000;
  padding: 8px 16px;
  text-decoration: none;
}

/* Change the link color on hover */
li a:hover {
  background-color: #555;
  color: white;
}

1 个答案:

答案 0 :(得分:0)

您需要从overflow: hidden中删除ul规则,否则该下拉列表将不可见。

ul {
      list-style-type: none;
      margin: 0;
      padding: 0;
      background-color: #e8d625;
      position: fixed;
      top: 0;
      width: 100%;
      z-index: 5;
    }
    
    li {
      float: left;
    }
    
    li a {
      display: block;
      color: #090909;
      text-align: center;
      font-weight: bold;
      padding: 14px 16px;
      text-decoration: none;
    }
    
    /* Change the link color to #111 (black) on hover */
    li a:hover {
      background-color: #f7e525;
    }
    
    .active {
      background-color: #f7e525;
    }
    
    .dropdown {
      float: left;
      overflow: hidden;
    }
    
    .dropdown .dropbtn {
      font-size: 16px;
      border: none;
      outline: none;
      color: #77ffb7;
      padding: 14px 16px;
      background-color: inherit;
      font-family: inherit; /* Important for vertical align on mobile phones */
      margin: 0; /* Important for vertical align on mobile phones */
    }
    
    .navbar a:hover, .dropdown:hover .dropbtn {
      background-color: #f7e525;
    }
    
    /* Dropdown content (hidden by default) */
    .dropdown-content {
      display: none;
      position: absolute;
      background-color: #80f987;
      min-width: 160px;
      box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    }
    
    /* Links inside the dropdown */
    .dropdown-content a {
      float: none;
      color: black;
      padding: 12px 16px;
      text-decoration: none;
      display: block;
      text-align: left;
      position: relative;
    }
    
    /* Add a grey background color to dropdown links on hover */
    .dropdown-content a:hover {
      background-color: #80f987;
    }
    
    /* Show the dropdown menu on hover */
    .dropdown:hover .dropdown-content {
      display: block;
    }
    
    
    
    
    ul.side {
  list-style-type: none;
  margin-top: 45px;
  padding: 0;
  width: 200px;
  background-color: #f1f1f1;
  height: 100%;
  position: fixed;
  z-index: 1;
}

.side li a {
  display: block;
  color: #000;
  padding: 8px 16px;
  text-decoration: none;
}

/* Change the link color on hover */
.side li a:hover {
  background-color: #555;
  color: white;
}
<div class="navbar">
<ul>
  <li><a href="default.asp">tekst</a></li>
  <li><a href="news.asp">tekst</a></li>
  <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>
    </div>
  </div>
</ul>
</div>

<ul class="side">
  <li><a href="default.asp">Calendar</a></li>
  <li><a href="news.asp">info1</a></li>
  <li><a href="contact.asp">info2</a></li>
  <li><a href="contact.asp">info3</a></li>
  <li><a href="contact.asp">info4</a></li>
</ul>