如何将悬停效果添加到引导导航菜单

时间:2019-02-06 19:58:36

标签: html css bootstrap-4

大家好,我是Web开发的新手,我正在尝试将导航效果添加到导航菜单中,类似于此链接中的第一个示例:https://codepen.io/Calloumi/pen/vndlH

我尝试对我的bootstrap html nav菜单实施相同的想法,但是我的行为略有不同,只有底部边框似乎向内移动,当我将鼠标悬停在链接上并悬停在链接上时,菜单项也会向上移动。我不确定需要添加/更改以使其以相同方式工作

.navbar-light .navbar-nav .nav-link {
  text-transform: uppercase;
  text-align: center;
  font-size: 13px;
  text-decoration: none;
  background: white;
  color: black;
  font-family: "open-sans";
  transition: 0.3s ease;
  border-top: 4px solid #FFFFFF;
  border-bottom: 4px solid #FFFFFF;
  padding: 20px 0;
  margin: 0 20px;
}

.navbar-light .navbar-nav .nav-link.active,
.navbar-light .navbar-nav .nav-link:hover {
  border-top: 4px solid #000000;
  border-bottom: 4px solid #000000;
  padding: 6px 0px;
  background: #11ADE8;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<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>
<nav class="navbar fixed-top navbar-expand-md navbar-light ">

  <div class="container-fluid">

    <a class="navbar-brand " href="#">
      <img src="images/logoblue.png" alt="">
    </a>
    <button class="navbar-toggler first-button darken-3" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
       <div class="animated-icon1"><span></span><span></span><span></span></div>
        </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Services</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Products</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Booking</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Prices</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Gallery</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Contact us</a>
        </li>
      </ul>
</nav>

对于实现与我的导航菜单相同的悬停效果,我们将不胜感激。

2 个答案:

答案 0 :(得分:0)

对于简单的导航,您有大量的HTML。您链接的codepen可以正确执行此操作。包裹在导航元素中的一组链接(即锚标记)。

正确的解决方案是简化HTML。

this
nav {
  margin-top: 40px;
  padding: 24px;
  text-align: center;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
  background: #3fa46a;
}

nav a {
  transition: 0.3s ease;
  background: #3fa46a;
  color: white;
  font-size: 20px;
  text-decoration: none;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  padding: 20px 0;
  margin: 0 5px;
  font-size: 17px;
}
nav a:hover {
  border-top: 4px solid white;
  border-bottom: 4px solid white;
  padding: 6px 0; 
}

答案 1 :(得分:0)

编辑:您需要从timestamp nameID Value accountID Count 02/02/2019 00:00:13 17730 Value 1 82607201 3 02/02/2019 00:00:14 17730 Value 2 82607201 1 02/02/2019 00:00:15 17730 Value 2 82607201 1 02/02/2019 00:00:16 17730 Value 2 82607201 1 02/02/2019 00:00:17 17730 Value 1 82607201 3 02/02/2019 00:00:18 17730 Value 2 82607201 1 02/02/2019 00:00:19 17730 Value 2 82607201 1 02/02/2019 00:00:20 17730 Value 2 82607201 1 02/02/2019 00:00:21 17730 Value 1 82607201 1 02/02/2019 00:00:22 17730 Value 2 82607201 样式中删除.navbar-light类,并将:hover用于display:inline,它将按预期工作。以下是注释中来自Codepen的更正代码。

navbar-nav