Bootstrap 导航栏菜单中的悬停过渡
Hover Transition in Bootstrap Navbar Menu
我找到了这个代码笔,其中 css 过渡用于在悬停时实现滑动效果。
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 以转换转换而不是左侧 属性。
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 过渡用于在悬停时实现滑动效果。 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 以转换转换而不是左侧 属性。
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;
}