html - 悬停 css 不起作用,容器元素留在白色背景中

标签 html css

我是 CSS 的新手,我想创建一个悬停菜单。悬停时下拉菜单完美呈现。在那之后,如果我将鼠标悬停在下拉项上,它就会被洗白。

这是我的 fiddle 和它的代码。谁能帮我解决这个问题。

设计应该如下图所示。

我试过右边那种三 Angular 形的形状。但是,它也被洗白了。

谁能帮我解决这个问题。

enter image description here

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>

最佳答案

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

尝试像下面这样的东西作为起点。将鼠标悬停在 p 元素上时移除 background: #fff; 并在鼠标悬停时为 a 元素文本添加某种颜色。

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

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

关于html - 悬停 css 不起作用,容器元素留在白色背景中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54135428/

相关文章:

Php - 如何根据url调整内容

javascript - React-router-dom v6 显示除默认 URL 之外的空白页面

RTL 形式的 HTML 标签

html - QMessageBox中如何给消息设置边框?

html - 如何更改 flex 子元素的祖先顺序

css - 如何更改 Font Awesome 5 中图标的颜色?

javascript - 单选按钮选择不起作用

html - 添加样式后字体样式不变

jquery - 动态地将列跨度和/或行跨度添加到表格单元格

jquery - 如何在悬停在文本区域的每个单词上时设置文本装饰下划线