Kevin Aartsen Kevin Aartsen - 1 month ago 16
HTML Question

bootstrap nav and fixed position not working

I'm using a bootstrap navigation bar. I positioned the navigation bar inside my image slider as you can see in the example. When i scroll down the navigation disappears, I dont want this. I want the navigation to follow me as i scroll down.
So i tried adding

position:fixed
. When i added position fixed the whole menu became different. I want it to maintain the full width.

https://jsfiddle.net/hqdg1w36/1/

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="resources/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">





<body>
<header>

<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Beauty Salon Lisa</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</div>
</nav>

<div id="myCarousel" class="carousel slide" data-ride="carousel">

<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>

<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">

<div class="item active">
<img src="https://cdn.spafinder.com/2016/01/spa-treatments-to-try.jpg" alt="Chania">
</div>

<div class="item">
<img src="https://cdn.spafinder.com/2016/01/spa-treatments-to-try.jpg" alt="Chania">
</div>

<div class="item">
<img src="https://cdn.spafinder.com/2016/01/spa-treatments-to-try.jpg" alt="Chania">
</div>

<div class="item">
<img src="https://cdn.spafinder.com/2016/01/spa-treatments-to-try.jpg" alt="Chania">
</div>

</div>

<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>

<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>


</div>
</header>
</body>

</html>


header {
}

.carousel {
position: absolute;
top: 0;
}

a.navbar-brand {
font-family: 'Pacifico', cursive;
}

nav.navbar.navbar-inverse {
border-radius:0;
background-color:rgba(0, 0, 0, 0.5);
border:none;
margin-bottom:0;
z-index:100;
top:0;


}


nav.navbar.navbar-inverse a {
color:#E897DB;
}

nav.navbar.navbar-inverse a:hover {
color:#F7BDFF;
}
.navbar-inverse .navbar-nav>.active>a, .navbar-inverse .navbar-nav>.active>a:focus, .navbar-inverse .navbar-nav>.active>a:hover {

color:#F7BDFF;
background:none;
}

GvM GvM
Answer

https://jsfiddle.net/hqdg1w36/2/ check this fiddle

<nav class="navbar navbar-inverse navbar-fixed-top">

</nav>
Comments