首页 > 解决方案 > 悬停css不起作用,容器元素留在白色背景中

问题描述

我是 CSS 新手,我正在尝试创建悬停菜单。悬停时,下拉菜单非常完美。之后,如果我将鼠标悬停在下拉项目上,它会被洗白。

这是我的小提琴和代码。任何人都可以帮我解决这个问题。

在下图中,设计应该看起来像这样。

我在右侧尝试过那种三角形的形状。但是,它也是白色的。

有人可以帮我解决这个问题。

在此处输入图像描述

nav ul li a:hover, .dropdown:hover .dropbtn{
  background-color: #EFF3F6;
}

nav ul li a {
  position: relative;
}

nav ul li a:hover:after {
 content: "";
 display: block;
 border-left: 10px solid transparent;
	border-right: 10px solid transparent;
	border-bottom: 10px solid #7B8B93;
 position: absolute;
 left: 35%;
 bottom: 0px;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #7b8b93;
  width: 100%;
  left: 0;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

nav ul li .dropdown:hover .dropdown-content {
  display: block;
}

.dropdown{
  position: initial;
}


.nav-link:hover + .dropdown .dropdown-content{
  display: block;
}

.one img:hover, .two img:hover, .three img:hover{
  opacity: 0.3;
}


.open-source p {
  border-top: 1px solid red;
  padding: 0;
  margin: 0;
}

.open-source p:last-child {
  border-bottom: 1px solid red;
}

.open-source p a {
  text-decoration: none;
  color: #fff;
  position: relative;
  font-size: 30px;
  width: 100%;
}

.open-source p:hover {
  background: #fff;
  border-left: 10px solid orange;
  color: #111;
}

.open-source p:hover a:after {
  content: "";
  display: block;
  border-top: 32px solid transparent;
  border-left: 15px solid #fff;
  border-bottom: 32px solid transparent;
  position: absolute;
  left: 100%;
  bottom: 0px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Logo</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto">
      <li class="nav-item">
        <a class="nav-link" href="#">Solutions</a>
        <div class="dropdown">
          <div class="dropdown-content">
            <div class="row">
              <div class="col-lg-4 open-source">
                <h3 class="ml-3">Open Source Solution Suites</h3>
                <p class="ml-3"><a class="commerce" href="#">Dr.Commerce</a></p>
                <p class="ml-3"><a class="universal" href="#">Universal Commerce</a></p>
                <p class="ml-3"><a class="emmerging" href="#">Emmerging Techlogies</a></p>
              </div>
              <div class="col-lg-8 services">
                <h3>Services & Technologies</h3>
                <ul class="list-inline">
                  <li class="list-inline-item one">
                    <img src="./images/twitter-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item two">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item one two">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item three">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item one two">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item two">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item three">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item two">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item one three">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item three">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item three">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                  <li class="list-inline-item two">
                    <img src="./images/instagram-xxl.png" width="60" height="67" alt="New York">
                  </li>
                </ul>
              </div>
            </div>
          </div>
        </div>
      </li>
    </ul>
  </div>
</nav>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>

标签: htmlcss

解决方案


p在悬停时将元素的背景设置为白色,这会导致您提到的“粉饰”效果。此外,您可能希望在悬停时更改a文本的颜色以使其可读。

尝试以下类似的方法作为起点。background: #fff;悬停在元素上时删除,并在悬停时为元素文本p添加某种颜色。a

.open-source p:hover {
  border-left: 10px solid orange;
  color: #111;
}

.open-source p:hover a {
  color: #000;
}

推荐阅读