下拉菜单的位置和样式

时间:2020-02-19 12:28:48

标签: html css

如何使鼠标悬停效果达到下拉菜单的全宽,并且使鼠标悬停在li而不是a上时文本会更改颜色。

因此它应该是黑色的下拉菜单,当li的背景上的每个链接都悬停时,应更改为rgba(255,255,255, 0.1),文本应更改为rgba(102,245,66, 0.8) li,而部分则不应溢出了正常的下拉部分(我尝试过overflow: hidden

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #1c1c1c;
  min-width: 240px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  padding: 12px 16px;
  z-index: 1;
  height: 300px;
  position: absolute;
  right: 0;
  top: 100;
}

ul {
  list-style: none;
  overflow: hidden;
}

li {
  font-size: 1em;
  text-align: center;
  padding-top: .5em;
  height: 75px;
  width: 240px;
  overflow: hidden;
}

a {
  color: #fff;
  text-decoration: none;
  font-size: 2rem;
  font-family: $main-font;
  width: 240px;
}

a:hover {
  color: rgba(102, 245, 66, 0.8);
}

li:hover {
  background: rgba(255, 255, 255, .2);
  color: #8FC3A1;
  width: 240px;
  cursor: pointer;
}

.dropdown:hover .dropdown-content {
  display: block;
}
<div class="dropdown">
  <span><i class="fa fa-bars">Just hover on it</i></span>
  <div class="dropdown-content">
    <ul>
      <li><a href="#home">Home</a></li>
      <li><a href="#about">About</a></li>
      <li><a href="#lin">Line Up</a></li>
      <li><a href="#contact">Contact</a></li>
    </ul>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

我不确定您是否正在寻找该标签,请让我知道它是否满足您的要求,解决方法是在我们将鼠标悬停在a上时更改li的颜色

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #1c1c1c;
  min-width: 240px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  padding: 0;
  z-index: 1;
  height: 300px;
  position: absolute;
  right: 0;
      left: 0;
}

ul {
  list-style: none;
  overflow: hidden;
  margin: 0;
    padding: 0;
}

li {
    font-size: 1em;
    text-align: center;
    margin-bottom: 10px;
}

li:hover {
  background: rgba(255,255,255, 0.1);
  color: #8FC3A1;
  cursor: pointer;
}
li:hover a{
  color: rgba(102,245,66, 0.8)
}


a {
  color: #fff;
  text-decoration: none;
  font-size: 2rem;
  font-family: $main-font;
  width: 240px;
}
.dropdown:hover .dropdown-content {
  display: block;
}
<div class="dropdown">
  <span><i class="fa fa-bars">fa-bar dropdown</i></span>
  <div class="dropdown-content">
    <ul>
      <li><a href="#home">Home</a></li>
      <li><a href="#about">About</a></li>
      <li><a href="#lin">Line Up</a></li>
      <li><a href="#contact">Contact</a></li>
    </ul>
  </div>
</div>