10

I am using the latest version of bootstrap. Kind of tried various things on my own and after that I thought I might find something on stackoverflow. But kind didn't get the thing. I mean how it works?

This is my code. I am not gonna add any custom style here since they didn't really work that well instead they created some error.

I also checked this post also Bootstrap - How to slide nav bar from left instead from top I tried all the answer from there but it didn't work for me.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">

    <nav class="navbar navbar-toggleable-md navbar-inverse fixed-top bg-inverse">
 <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
 <span class="navbar-toggler-icon"></span>
 </button>
 <a class="navbar-brand" href="">Roknil Style</a>
 <div class="collapse navbar-collapse" id="navbarCollapse">
  <ul class="navbar-nav mr-auto">
   <li class="nav-item active">
    <a class="nav-link" href="#">Home</a>
   </li>
   <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
   </li>
   <li class="nav-item">
    <a class="nav-link" href="#">About</a>
   </li>
  </ul>
  <form class="form-inline mt-2 mt-md-0">
  <input class="form-control mr-sm-2" type="text" placeholder="Search">
  <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </form>
   </div>
    </nav>

<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
Community
  • 1
  • 1
ramzan00
  • 143
  • 1
  • 2
  • 11
  • Possible duplicate of [Bootstrap - How to slide nav bar from left instead from top](http://stackoverflow.com/questions/31641352/bootstrap-how-to-slide-nav-bar-from-left-instead-from-top) – shaochuancs May 12 '17 at 07:24
  • I checked the post before and I tried the answers there was. But the result was not that much satisfying. – ramzan00 May 12 '17 at 08:40
  • @shaochuancs this isnt a duplicate as the other question is for bootstrap 3 – Tom Jul 17 '17 at 10:01

4 Answers4

28

You can override the transition styles for the navbar-collapse like this...

Demo

@media (max-width: 992px) {
    .navbar-collapse {
        position: fixed;
        top: 50px; /* adjust to height of navbar */
        left: 0;
        padding-left: 15px;
        padding-right: 15px;
        padding-bottom: 15px;
        width: 75%;
        height: 100%;
    }

    .navbar-collapse.collapsing {
        left: -75%;
        transition: height 0s ease;
    }

    .navbar-collapse.show {
        left: 0;
        transition: left 300ms ease-in-out;
    }

    .navbar-toggler.collapsed ~ .navbar-collapse {
        transition: left 500ms ease-in-out;
    }
}

Demo - slide from right
Demo - slide from left
Demo - slide from left (full height)

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
  • Actually I had edit quite a bit from this code and it works but not quite satisfying so I will keep trying on that and if possible someone might share some better solution. – ramzan00 May 12 '17 at 16:10
3

Actually, you can use @Hrvoje Golcic's solution to implement the slide-from-left effect.

I checked your code and fixed some issues. Please check the following code snippet. You may need to define more CSS rules to style the navigation bar.

$(function(){
  // mobile menu slide from the left
  $('[data-toggle="slide-collapse"]').on('click', function() {
    $navMenuCont = $($(this).data('target'));
    $navMenuCont.animate({'width':'toggle'}, 280);
  });
})
    #navbarCollapse {
      position: fixed;
      top: 0;
      left: 0;
      z-index: 1;
      width: 280px; /*example + never use min-width with this solution */
      height: 100%;
      background: #000;
    }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">

    <nav class="navbar navbar-toggleable-md navbar-inverse fixed-top bg-inverse">
 <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="slide-collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
 <span class="navbar-toggler-icon"></span>
 </button>
 <a class="navbar-brand" href="">Roknil Style</a>
 <div class="collapse navbar-collapse" id="navbarCollapse">
  <ul class="navbar-nav mr-auto">
   <li class="nav-item active">
    <a class="nav-link" href="#">Home</a>
   </li>
   <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
   </li>
   <li class="nav-item">
    <a class="nav-link" href="#">About</a>
   </li>
  </ul>
  <form class="form-inline mt-2 mt-md-0">
  <input class="form-control mr-sm-2" type="text" placeholder="Search">
  <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </form>
   </div>
    </nav>

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
Community
  • 1
  • 1
shaochuancs
  • 15,342
  • 3
  • 54
  • 62
1

The above CSS override does work. However, you have to wait for the height to transition first - causing a bit of a delay. The code below solves that.

 @media (max-width: 768px) {
        .navbar-collapse {
            position: fixed;
            top: 0;
            left: 0;
            padding-left: 15px;
            padding-right: 15px;
            padding-bottom: 15px;
            width: 75%;
            height: 100%;
        }

        .navbar-collapse.collapsing {
            left: -75%;
            transition: height 0s ease;
        }

        .navbar-collapse.show {
            left: 0;
            transition: left 500ms ease-in-out;
        }

        .navbar-toggler.collapsed ~ .navbar-collapse {
            transition: left 500ms ease-in-out;
        }
    }
Dustin
  • 11
  • 1
0
@media(max-width:768px){
.navbar-collapse {
      position:fixed;
      left: 0%;
      padding: 15px;
      width:100%;
      top:0%;
      height:100%;
  }
  
  .navbar-collapse.collapsing {
      height: auto;
      -webkit-transition: left 0.3s ease;
      -o-transition: left 0.3s ease;
      -moz-transition: left 0.3s ease;
      transition: left 0.3s ease;
      left: -100%;
  }
  .navbar-collapse.show {
      left: 0;
      -webkit-transition: left 0.3s ease-in;
      -o-transition: left 0.3s ease-in;
      -moz-transition: left 0.3s ease-in;
      transition: left 0.3s ease-in;
  }
}