Bootstrap 4动画导航栏不显示

时间:2018-09-21 03:19:00

标签: html css twitter-bootstrap twitter-bootstrap-3 bootstrap-4

我正在尝试实现动画导航栏,其中图标栏变成X。我记得在Bootstrap 3中这样做很好,但对于Bootstrap 3来说似乎不起作用,并且折叠的菜单图标栏甚至没有显示在页面上?

HTML

<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
  <div class="container">
<a class="navbar-brand" href="#">Start Bootstrap</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
      <span class="icon-bar top-bar"></span>
      <span class="icon-bar middle-bar"></span>
      <span class="icon-bar bottom-bar"></span>
      <span class="sr-only">Toggle navigation</span>
    </button>
<div class="collapse navbar-collapse" id="navbarResponsive">
  <ul class="navbar-nav ml-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="#">About</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Services</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Contact</a>
    </li>
  </ul>
</div>

CSS

.navbar-toggler {
border: none;
background: transparent !important;
}

.navbar-toggler:focus {
outline: none;
background: transparent !important;
}

.navbar-toggler .icon-bar {
background-color: #fff;
transform: rotate(0deg) translate(0px, 0px);
transition: ease all .2s;
}

.navbar-toggler .icon-bar {
display: block;
width: 22px;
height: 2px;
border-radius: 1px;
}

.navbar-toggler .icon-bar+.icon-bar {
margin-top: 4px;
}

.icon-bar:nth-child(2) {
width: 16px;
transition: ease all .2s;
}

.navbar-toggler:hover>.icon-bar:nth-child(2) {
width: 22px;
transition: ease all .2s;
}

.navbar-toggler:active>.icon-bar:nth-child(2) {
width: 22px;
transition: ease all .2s;
}

.navbar-toggler:not(.collapsed) .icon-bar:nth-child(1) {
transform: rotate(45deg) translate(5px, 4px);
transition: ease all .2s;
}

.navbar-toggler:not(.collapsed) .icon-bar:nth-child(2) {
opacity: 0;
transition: ease all .2s;
}

.navbar-toggler:not(.collapsed) .icon-bar:nth-child(3) {
transform: rotate(-45deg) translate(4px, -4px);
transition: ease all .2s;
}

1 个答案:

答案 0 :(得分:0)

您提供的代码运行正常。我认为您的CSS由于某种原因未在申请。 请检查以下链接。

[https://jsfiddle.net/Kunshtech/q41fcnzs/][1]