Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Bootstrap static-navbar overlay content like fixed-navbar

Using bootstrap 3. I have a full-screen hero/intro section that has a background pattern.

WHAT I WANT:

  1. A static navbar that overlays this hero section so that the background pattern of the hero section shows in the background of the navbar (like it would if I used "navbar-fixed-top" instead of "navbar-static-top").

What I want it to look like (navbar-fixed-top style): desired look

  1. When navbar collapses in mobile-view, the hamburger icon shows the navbar links without pushing down the hero section.

desired look

WHAT HAPPENS:

  1. Using "static" stacks navbar section before hero section instead of overlaying it actual look
  2. Pressing hamburger icon pushes down hero section instead of overlaying it enter image description here

Any idea how I could accomplish this without giving the hero section a negative margin?

My HTML:

<nav class="navbar navbar-static-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-main-collapse">
                <i class="fa fa-bars"></i>
            </button>
            <div class="navbar-brand" href="#page-top">
                <img src="http://placehold.it/200x80" alt=" Logo" width="100">
            </div>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div id="navbar-main-collapse" class="collapse navbar-collapse navbar-right">
            <ul class="nav navbar-nav">
                <li class="active"><a href="..." target="_blank"><i class="fa fa-folder-open"></i> Link 1</a></li>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

<section id="hero" class="full-screen-section">
    <div class="cell-mid">
        <div class="section-body">
            <div class="container">
                <div class="row">
                    <div class="col-md-2 col-md-offset-1 text-right">
                        <img src="http://placehold.it/300x120" id="faceOne" class="img-max hidden-xs hidden-sm">
                    </div>
                    <div class="col-md-6 text-left">
                        <h1 class="brand-heading">EXAMPLE HEADING</h1>
                    </div>
                    <div class="col-md-2 text-left">
                        <img src="http://placehold.it/300x120" id="faceTwo" class="img-max hidden-xs hidden-sm">
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

My CSS:

/* --------------- Nav --------------- */

.navbar {
    padding: 1em 0;
    margin-bottom: 0;
    border: none;
    text-transform: uppercase;
    background-color: transparent;
    background-image: none;
}

.navbar a {
    color:#fff;
}

/* --------------- Hero --------------- */

#hero {
    display: table;
    width: 100%;
    height: 100%;
    padding: 200px 0 50px 0;
    text-align: center;
    color: #fff;
    background: linear-gradient(
      rgba(248, 153, 153, 0.68), 
      rgba(248, 153, 153, 0.68)), url('bg-science.png');
    -webkit-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.5);
    -moz-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.5);
    box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.5);
}

EDIT: Solution found, thanks to @airbean. Just used the navbar-fixed-top class and added "position: absolute" on the navbar class.

like image 989
clavid Avatar asked Mar 11 '15 19:03

clavid


People also ask

How do I create a fixed navigation bar in bootstrap?

Set the navbar fixed to the top, add class . navbar-fixed-top to the . navbar class.

How do you make an overlapping navbar?

To make the nav bar and top bar scroll normally, you may go to Appearance > Customize > Header > Navbar Position > Select: Static Top.

How can make navbar fixed top in bootstrap 4?

Use the .sticky-top class to make the navbar fixed/stay at the top of the page when you scroll past it.


1 Answers

@Aibrean helped out. I used the navbar-fixed-top class and added "position: absolute" on the navbar class.

like image 169
clavid Avatar answered Dec 30 '22 18:12

clavid