I have a Bootstrap template that came in an index.html file. I need to add some c# code, so I moved it over to an Default.aspx page.
Everything works, but the page loads with a seemingly random nav item highlighted(Is this active). The page loads with the Contact nav item highlighted. I tried setting the active class to the Home item.
<!-- Navigation -->
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top navbar-custom">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span> Menu <i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="#page-top">Home</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="hidden">
</li>
<li class="page-scroll active">
<a data-toggle="tab" href="#page-top">Home</a>
</li>
<li class="page-scroll">
<a data-toggle="tab" href="#portfolio">Demo's</a>
</li>
<li class="page-scroll">
<a data-toggle="tab" href="#screens">Screen Shots</a>
</li>
<li class="page-scroll">
<a data-toggle="tab" href="#new">New Things</a>
</li>
<li class="page-scroll">
<a data-toggle="tab" href="#about">About</a>
</li>
<li class="page-scroll">
<a data-toggle="tab" href="#contact">Contact</a>
</li>
<li class="page-scroll">
Resume
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
The highlighting is not random, but rather coming from the .active class. If your above example, Home will be highlighted. Whichever nav element has the 'active' class will be the one that is highlighted. I've created an example showcasing this by changing Screen shots to active here.
If you want the Contact page to be highlighted, you need to set that tab as active:
<li class="page-scroll active">
<a data-toggle="tab" href="#contact">Contact</a>
</li>
For changing between multiple pages, you'll want to output this active class manually through your back-end code. There's already a great answer on how to do that in C# here.
Hope this helps! :)
Related
I can see the navbar however when I click it to have dropdown it is not responding.
<!-- Navbar -->
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
<a class="navbar-brand" href="#">
<!-- Logo -->
My name
</a>
<!-- collapse when screen get small -->
<button type="button" class="navbar-toggler" data-toggle="collapse"
data-target=".navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<!-- ml-auto: Setting navbar to right -->
<ul class="nav navbar-nav ml-auto">
<!-- active class makes current location brighter -->
<li class="nav-item">
<!-- #home goes to <div id="home"> -->
<a class="nav-link" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about_me">About Me</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#projects">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#References">References</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
</ul>
</div>
</nav>
I am using bootstrap4 and all the classes are from bootstrap. Thanks in advance!
HTML/CSS looks good. Make sure you're including jQuery, poppper.js and bootstrap.js in that order or else any functionality that depends on it will not work.
Pasted it into this codepen and it works fine.
I've the following HTML NavBar:
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top navbar-custom" style="margin-bottom : 0px;">
<div class="container-fluid" ng-controller = "NavController">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span> Menu <span ng-show="userCart.cart_size>0" style="color:orange">({{userCart.cart_size}}) </span><i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="#page-top">XYZ IoT</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="hidden">
</li>
<li class="page-scroll">
Products
</li>
<li class="page-scroll">
About
</li>
<li class="page-scroll">
Contact
</li>
<!-- Add the Login Anchor -->
<li ng-if="!userInfo.authorization">
Login
</li>
<li ng-if="userInfo.authorization">
My Devices
</li>
<li ng-if="userInfo.authorization">
Logout
</li>
</ul>
</div>
</div> <!-- /.navbar-collapse -->
</nav>
The problem is : When the compressed Nav appears, and I click on it, the menu items appear -- so far fine. But as soon I click else where, the menu stays as is. I have to click on the Menu (3 lines) to make menu items to disappear.
Can it be accomplished? I'm using bootstrap
I am sorry if this is a repeat but I have searched and tried info I have found. Currently when on a mobile, my menu button doesn't drop down or enable me to select any other parts of the menu.
<!-- Navigation -->
<nav id="mainNav" class="navbar fixed-top navbar-toggleable-md navbar-light">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarExample" aria-controls="navbarExample" aria-expanded="false" aria-label="Toggle navigation">
Menu <i class="fa fa-bars"></i>
</button>
<div class="container">
<a class="navbar-brand" href="#page-top">Chunky Geek</a>
<div class="collapse navbar-collapse" id="navbarExample">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" title="about" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" title="services" href="services.html">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" title="portfolio" href="#portfolio">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" title="follow" href="#follow">Follow</a>
</li>
<li class="nav-item">
<a class="nav-link" title="contact" href="contact.html">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
I don't have enough rep to comment, so i'll send this as an answer.
Are you sure you have included both the css and js of bootstrap? For example, does this collapsible work?
<button data-toggle="collapse" data-target="#demo">Collapsible</button>
<div id="demo" class="collapse">
Lorem ipsum dolor text....
</div>
Looks like it is working for me in THIS FIDDLE
Make sure you are using the proper Bootstrap CDN for both CSS and JS. If they aren't all loaded and linked properly, it will not work. v3.3.7 and v4 are blelow:
Bootstrap v4
Bootstrap v3.3.7
I Use this template, build with boostrap4
Can you help me to add Hover DropDown Menubar in this above template ?
I update index.html file with some code to show Dropdown menubar, now its shown, but I need to show menu on hover.
Here Is Code:
<!-- Navigation -->
<nav class="navbar fixed-top navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarExample" aria-controls="navbarExample" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="container">
<a class="navbar-brand" href="/"><img src="img/km-logo.png" style="margin-bottom:5px;" width="60%" height="auto" alt="kmwebsoft.com logo"></a>
<div class="collapse navbar-collapse dropdown" id="navbarExample">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="dropdown">
<li class="dropdown"> Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li class="dropdown-item">Action</li>
<li class="dropdown-item">Another action</li>
<li class="dropdown-item">Something else here</li>
</ul>
</li>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<span class="text-primary"></span>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
Can you suggest any idea ? I apply menu on AboutUs temporary.
You Have to use javascript or jquery to do this.bind event on the menu item where you want dropdown menu.
I have this navbar. It works great in regular screen width, but when collapsed, the mobile navbar button doesn't work. I've tried to find any unclosed divs and other issues but can't identify any. Thanks in advance for any help! Apologies for the beginner question
<nav class="navbar navbar-default" 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-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-brand" href="#">
<div class="text-center">
<img alt="nav" src="/assets/navbar.png" />
</div>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<h4>
<ul class="nav navbar-nav navbar-left">
<!-- <li> Help </li>-->
<li> Buy </li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li> Search </li>
<li class="dropdown">
My purchases<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li> My profile </li>
<li class="divider"></li>
<li> Items bought </li>
<li> Items sold </li>
<li class="divider"></li>
<li> Purchase history </li>
</ul>
</li>
<li class="dropdown">
Settings <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li> Edit my profile </li>
<li> Manage my profile </li>
<li class="divider"></li>
<li class="dropdown-header">GOODBYE </li>
<li> <a data-method="delete" href="/users/sign_out" rel="nofollow">Logout</a> </li>
</ul>
</li>
</div><!-- /.navbar-collapse -->
</nav>
</h4>
Clean-up your HTML and it should work fine. There are several missing close tags (/ul, /div) and the /h4 is closed at the end.
http://bootply.com/ytu2dul2yw