Evolis Evolis - 4 months ago 13
CSS Question

How do i change the Navbar Position when Bootstrap goes responsive

The desktop view of the website got a logo and a navigation under it.

I want the position of the navigation to become above the logo (and also create a little space between the logo and navbar) when it switches to mobile view.

Here is desktop view:

desktop

Mobile view:

mobile

What I want mobile view to be:

how I want mobile




HTML:

<div class="text-center logo">
<a href="index.html"><img src="img/brand.png" /></a>
<span class="brand-headline visible-desktop">
<p class="title-text">Example</p>
</span>
</div>

<!-- =begin navigation !-->
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-target">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand brand" href="#">Brand</span>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-target">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Schuhe</a></li>
<li><a href="#">Link</a></li>
</div><!-- /.navbar-collapse -->
</div>
</nav>

Answer

Until there's more support for FlexBox the way I do it is to clone it with jQuery. I do it all the time since BS3 menu requires jQuery anyway.

THE DEMO: http://jsbin.com/oVifowe/1/

/* __________________ Mobile Menu __________________*/
 $(document).ready(function() {

 $('.navbar').clone().removeClass('hidden-xs').appendTo('.mobile-menu');

 }); //end

The HTML:

 <div class="mobile-menu visible-xs"><!--MENU CLONES HERE--></div>

 <div class="text-center logo">
    <a href="index.html"><img src="img/brand.png" /></a>
    <span class="brand-headline visible-desktop">
        <p class="title-text">LOGO</p>
    </span>
</div>

<!-- begin navigation !-->
<nav class="navbar navbar-default hidden-xs" role="navigation">
  <!-- Brand and toggle get grouped for better mobile display -->
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-target">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>

  <!-- Collect the nav links, forms, and other content for toggling -->
  <div class="collapse navbar-collapse" id="navbar-target">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Schuhe</a></li>
      <li><a href="#">Link</a></li>
  </div><!-- /.navbar-collapse -->
  </div>
</nav>
Comments