简体   繁体   中英

Navbar to overlay background color & image

Question 1: I want to have my navbar affix overlay on top of the background color & background image of div ( top-banner ), for now when I scroll down. the background color will overlay my navbar affix instead.

How do I achieve such that my navbar will on top of my background color for the div class top-banner.

There 1 more issue which is my navbar that sort of having margin left on itself, when I added data-spy affix, the navbar move slightly to the right, causing white space on the left and when I rescale my screen to smaller device size, the navbar collapse menu is unclickable unless I click slightly to the extreme right, which then toggle the menu. I not sure why affix got such issues. How do I fix it.

THANKS FOR HELPING to resolve this issues!!

Below is my code

    <html>
    <head>
    <title>Demo</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type="text/css">
    .navbar-header,
    .navbar-brand {
        line-height: 100px;
        height: 100px;
        padding-top: 0;
    }
    .affix .navbar-default {
        position: fixed !important;
        top: 0 !important;
        width: 100% !important;
        background-color: #957595 !important;
    }
    .affix {
        width: 100% !important;
    }
    @media screen and (min-width: 768px) {
    .navbar-header {
        padding-left: 200px;
        text-align: center;
    }
    }
.top-banner{
    background-color: #b0c4de;
    background-image: url("bi-uk-office7-2.jpg");
    background-repeat: no-repeat;
    background-position: right top;
}
    </style>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    </head>
    <body>
    <div class="container-fluid">
            <!-- Static navbar -->
         <div id="nav" data-spy="affix">
          <nav class="navbar navbar-default" style="background-color:black;background: rgba(0,0,0,0.9);">
            <div class="container-fluid">
              <div class="navbar-header 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>
                <a class="navbar-brand" href="#">Logo</a>
              </div>
              <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                  <li><a href="#"><font color="white">Link 1</font></a></li>
                  <li><a href="/list"><font color="white">Link 2</font></a></li>
                  <li><a href="/list"><font color="white">Link 3</font></a></li>
              </div><!--/.nav-collapse -->

   </div>
      </nav>
</div>

<section>
<div class="col-xs-12">

<div class="top-banner">
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
<hr>
</div>

</div>
</section>



</div>
</body>
</html>

Add a z-index to your #nav as below to be on top and add margin-left property to the same to stay of extreme left as it is getting padding from its parent container-fluid

#nav
{
     z-index:1000;
     margin-left: -15px;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM