gpt4 book ai didi

css - Bootstrap 导航栏菜单中的悬停过渡

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

我找到了这个 codepen,其中使用 css transition 来实现悬停时的滑动效果。 http://codepen.io/tdevine33/pen/CnDyv但我无法让它在我的 Bootstrap 导航栏上运行。是否与 Bootstrap 中的菜单不兼容?

 <!-- Static navbar -->
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.php">Index</a></li>
<li><a href="#">Link1</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link3</a></li>

<li class="dropdown">
<a href="#.php" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">LinkTest<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Linktest 2</a></li>
<li><a href="#">Linktest 3</a></li>
</ul>

<li><a href="kontakt.php">Kontakt</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>

最佳答案

为了支持下拉菜单,最初的 codepen 需要做一些调整。我还更改了 css 以转换转换而不是 left 属性。

demo

html:

<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>

</button>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav list-hover-slide">
<li><a href="index.php">Index</a>
</li>
<li><a href="#">Link1</a>
</li>
<li><a href="#">Link2</a>
</li>
<li><a href="#">Link3</a>
</li>
<li class="dropdown"> <a href="#.php" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">LinkTest<span class="caret"></span></a>

<ul class="dropdown-menu" role="menu">
<li><a href="#">Linktest 2</a>
</li>
<li><a href="#">Linktest 3</a>
</li>
</ul>
<li><a href="kontakt.php">Kontakt</a>
</li>
</ul>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>

CSS:

.list-hover-slide>li {
position: relative;
overflow: hidden;
}
.list-hover-slide>li>a {
z-index: 1;
transition: .35s ease color;
}
.list-hover-slide>li>a:before, .list-hover-slide>li.dropdown.open>a:before {
content:'';
display: block;
z-index: -1;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
transform: translateX(-100%);
border-right: solid 5px tomato;
background: gray;
transition: .35s ease transform;
}
.list-hover-slide>li>a:hover:before, .list-hover-slide>li.dropdown.open>a:before {
transform: translateX(0);
}
.list-hover-slide>li.dropdown.open {
overflow: initial;
}

关于css - Bootstrap 导航栏菜单中的悬停过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28265202/

24 4 0