将鼠标悬停在引导导航栏菜单中



我找到了这个代码笔,其中使用css过渡来存档悬停时的滑动效果。http://codepen.io/tdevine33/pen/CnDyv但是我无法让它在我的引导导航栏上工作。它与引导程序中的菜单不兼容吗?

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

原始代码笔需要一些调整才能支持下拉菜单。 我还更改了 css 以转换转换而不是 left 属性。

演示

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

相关内容

  • 没有找到相关文章

最新更新