gpt4 book ai didi

jquery - 悬停导航栏时如何使网页变暗,就像引导模式一样?

转载 作者:太空宇宙 更新时间:2023-11-04 01:14:04 24 4
gpt4 key购买 nike

是否可以使用 Bootstrap 在模态打开时使页面变暗时使用的相同过程?

我希望它能在我将鼠标悬停在引导导航栏上时使页面变暗。
当然,我不希望导航栏变暗!

modal-dim 是如何工作的?
我可以使用相同的 css 吗?

最佳答案

您可以使用所有主流浏览器都支持的纯 CSS 来做到这一点。

.navbar:hover+.nav-sibling {
display: block;
opacity: 0.5;
background: rgba(0, 0, 0, 1);
transition: opacity .15s linear;
}

.nav-sibling {
position: fixed;
display: none;
overflow: hidden;
outline: 0;
/* equal to the navbar height */
top: 56px;
bottom: 0;
left: 0;
right: 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</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 mr-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="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<div class="nav-sibling">

</div>
<footer class=" container-fluid bg-dark text-white py-5">
<div class="row">
<div class="col-12">
<h6>Lorem ipsum</h6>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget sapien dolor. Nam aliquam augue ante, et sodales felis vulputate iaculis.</p>
</div>
</div>
</footer>

nav-sibling 除了 top 属性外,与引导模态代码相同。


更新

Opacity sets the opacity value for an element and all of its children; While RGBA sets the opacity value only for a single declaration. - StackOverflow - opacity vs RGBA

最好为 alpha channel 使用 01 之间的数字,而不是 不透明度。在下面的代码中,我使用了 0.9

.navbar:hover+.nav-sibling {
display: block;
background-color: rgba(0, 0, 0, 0.9);
transition: all .15s linear;
}

关于jquery - 悬停导航栏时如何使网页变暗,就像引导模式一样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50591928/

24 4 0