gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 14:27:03 25 4
gpt4 key购买 nike

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

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

.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>

非常感谢任何有助于实现与我的导航菜单相同的悬停效果的帮助。

最佳答案

您有大量的 HTML 用于简单的导航。您链接的代码笔正确执行。一组包含在导航元素中的链接(即 anchor 标记)。

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

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;
}
<nav>
<a href="#">Home <span class="sr-only">(current)</span></a>
<a href="#">Services</a>
<a href="#">Products</a>
<a href="#">Booking</a>
<a href="#">Prices</a>
<a href="#">Gallery</a>
<a href="#">Contact us</a>
</nav>

关于html - 如何将悬停效果添加到引导导航菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54561596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com