gpt4 book ai didi

css - Bootstrap 4 Navbar Hover BG 颜色

转载 作者:太空宇宙 更新时间:2023-11-04 07:31:34 25 4
gpt4 key购买 nike

我的导航栏有问题。在非移动版本上(或当浏览器展开时),我希望悬停在链接上的背景颜色填充导航栏的高度,而不是它只是部分着色。

请告诉我如何在悬停每个链接时获得完整的背景颜色。谢谢!

a,
a:visited,
a:hover,
a:active {
color: inherit;
}


/* Navigation Bar */

.navbar {
background-color: #303030;
}

.navbar-nav a {
color: #ffffff;
text-align: center;
}

.navbar .navbar-nav>a:hover,
.navbar .navbar-nav>a:focus {
color: #ffffff;
background-color: yellow;
}


/*Mobile menu icon color*/

.navbar .navbar-toggler {
border-color: rgb(255, 255, 255);
}

.navbar .navbar-toggler-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255,255,255, 0.7)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}


/* Branding Dimension for Mobile */

.navbar-brand img {
width: 125px;
height: 29px;
}

@media (min-width: 576px) {
.navbar-brand img {
width: 195px;
height: 45px;
}
}
<!doctype html>
<html lang="en">

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="assets\css\style.css">

<title>Street Scents</title>
</head>

<body>
<nav class="navbar navbar-expand-lg">
<a class="navbar-brand" href="#">
<img src="assets/img/logo-text.png" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav ml-auto">
<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">About</a>
<a class="nav-item nav-link" href="#">Videos</a>
<a class="nav-item nav-link" href="#">Blog</a>
<a class="nav-item nav-link" href="#">Merch</a>
</div>
</div>
</nav>



<!-- Optional JavaScript -->
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>

</html>

最佳答案

只需将 py-0 Bootstrap 类添加到 Navbar 即可删除顶部/底部填充,以便您的自定义悬停颜色填充高度。要保持原始高度,请将顶部/底部填充添加到 nav-link

https://www.codeply.com/go/4ZBnt0gWFc

<nav class="navbar navbar-expand-lg py-0">
<a class="navbar-brand" href="#">
<img src="assets/img/logo-text.png" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav ml-auto">
<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">About</a>
<a class="nav-item nav-link" href="#">Videos</a>
<a class="nav-item nav-link" href="#">Blog</a>
<a class="nav-item nav-link" href="#">Merch</a>
</div>
</div>
</nav>

更改链接或悬停颜色的 CSS:

/* change the link color */
.navbar-nav .navbar-nav .nav-link {
color: rgba(255,255,255,.5);
}

/* change the color of active or hovered links */
.navbar-nav .nav-item.active .nav-link,
.navbar-nav .nav-item:hover .nav-link {
color: #ffffff;
}

关于css - Bootstrap 4 Navbar Hover BG 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49353534/

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