I have a Bootstrap 3 Navbar that has two right-justified <ul> sections which gives me this:
When the menu is collapse for mobile, I get this:
I have two questions related to the collapsed menu. 1) How can I get the buttons to appear at the bottom of the collapsed menu instead of the top? 2) How can I change the styling of the buttons in the collapsed menu (without affecting the style in the horizontal menu)?
Below is the markup for this Navbar. And yes I have a reason for having two separate <ul> sections:
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
My Site
</div>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li>Button One</li>
<li>Button Two</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</div>
</div>
</div>
I ended up finding a simpler solution for the reformatting and reordering of the button links on the collapsed navbar, one that doesn't require new javascript code:
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right hidden-xs">
<li>Button One</li>
<li>Button Two</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
<ul class="nav navbar-nav visible-xs">
<li><a href="#" >Button One</a></li>
<li><a href="#" >Button Two</a></li>
</ul>
</div>
I simply duplicated the Button One and Button Two <ul> section and added it to the bottom. I then removed the classes and ID on the <a> links so that no button formatting would occur. Finally, I added the hidden-xs bootstrap class to the top <ul> and visible-xs to the bottom <ul> class. That did the trick:
I ran into a similar issue but have been using Bootstrap 4.4 and this can be solved with a simple d-none d-block solution.
<ul class="nav justify-content-center">
<li class="nav-item d-sm-none d-md-block">
<a class="nav-link" href="#">Item 1</a>
</li>
<li class="nav-item d-sm-none d-md-block">
<a class="nav-link" href="#">Item 2</a>
</li>
<li>
<li class="nav-item">
<a class="nav-link" href="#">Item 3</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item 4</a>
</li>
<li class="nav-item d-none d-sm-block d-md-none">
<a class="nav-link" href="#">Item 1</a>
</li>
<li class="nav-item d-none d-sm-block d-md-none">
<a class="nav-link" href="#">Item 2</a>
</li>
</ul>
Using this method allows for items 1 and 2 to only appear after the display is set to small and below. While also hiding the originals at that same display size.
Related
I am creating a navbar for my page with the help of bootstrap. I have used <li> tags but I am not sure why the items are not quite on the same line. Please review the below code:
<nav class="navbar navbar-expand-lg">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">HOME</a>
</li>
<li class="nav-item">
<i class="fa-solid fa-chevron-right"></i>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CATEGORY </a>
</li>
</ul>
</nav>
Here's the screenshot of my output:
Use flex box.
For example you have to make navbar which have logo, links, menu Icon
So,
<nav class="d-flex justify-content-between align-items-center">
<div> logo </div>
<div>
<ul class="d-flex justify-content-between align-items-center">
<li>link1</li>
<li>link1</li>
<li>link1</li>
</ul>
</div>
</nav>
For, further more clarification visit: https://getbootstrap.com/docs/4.0/utilities/flex/
I'm using a colorlib template called faithful: https://colorlib.com/wp/template/faithful/
Basically I changed the css and the navbar to a horizontal one, the problem is when I view it in mobile, it doesn't work
This is what I did to change the navbar to a horizontal one
<div class="site-navbar-wrap js-site-navbar bg-white">
<div class="container">
<div class="site-navbar bg-light">
<div class="py-1">
<div class="row align-items-center">
<div class="col-2">
<a class="d-block" href="index.html" rel="home"><img class="d-block" src="images/company_logo.png" alt="logo"></a>
</div>
<div class="col-10">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<ul class="navbar-default" id="menu">
<li class="active">
Home
</li>
<a class="dropdown-toggle fa" data-toggle="dropdown" href="about.html" >About Us<span></span></a>
<ul class="dropdown-menu">
<li>Our Company</li>
<li>Team</li>
<li>Goals</li>
<li>Location</li>
</ul>
<li>Products</li>
</li>
<li>Merchandise</li>
<li>FAQs</li>
<li>Contact Us</li>
</ul>
</div>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
I want the navbar to work on mobile (showing a button on the right)
I tried everything I could but it still doesn't work and I've already finished the design of the website, I just really need to change the navbar.
<nav class="navbar navbar-expand-lg navbar-dark primary-color">
<!-- Collapse button -->
<button class="navbar-toggler float-xs-right" type="button" data-toggle="collapse" data-target="#basicExampleNav"
aria-controls="basicExampleNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Collapsible content -->
<div class="collapse navbar-collapse" id="basicExampleNav">
<!-- Links -->
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Our company</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">team</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">goals</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">location</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">merchandise</a>
</li>
</ul>
</div>
</nav>
you can modify and use this
I have this simple code in HTML using Bootstrap classes to create a navigation bar. I want my navigation bar to be horizontal so I added the navbar-inverse class. However, my navigation bar keeps showing vertical and I can't figure out why it does that even thought I tried different things to fix it.
<div class="blog-masthead">
<div class="container">
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav">
<li class="nav-item"><a class="blog-nav-item active" href="#">Home</a></li>
<li class="nav-item"><a class="blog-nav-item" href="#">New features</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item"><a class="blog-nav-item" href="#">{{ Auth::user()->name }}</a></li>
</ul>
</nav>
</div>
</div>
I hope navbar-inverse is nothing to do with menu view style I hope it's used to change the color of the menu text and for the view style you should use nav-link in a tag and nav-toggleable in nav tag I hope it's the answer.
I'm sorry if I misunderstood your question
<ul class="nav navbar-nav ">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link " href="#">New features</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item"><a class="nav-item" href="#">{{ Auth::user()->name }}</a></li>
</ul>
</nav>
</div>
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! :)
This is probably very simple, but the answer seems to be eluding me. I have tried several combinations using navbar-text, but most of them end up putting the text either above or below another navbar item. I would like the text to be located just to the left of the "Sign In" link.
Here is what I have now:
<nav class="navbar navbar-fixed-top navbar-dark bg-inverse">
<a class="navbar-brand" href="#">Sample App</a>
<ul class="nav navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
<div class="nav navbar-nav pull-md-right">
<div class="nav nav-item">
<p class="navbar-text">Signed in as User#1234</p>
</div>
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Sign In</a>
</li>
</ul>
</div>
</nav>
That ends up looking like this:
Many thanks in advance.
I think it is because of the div block here:
<div class="nav nav-item">
<p class="navbar-text">Signed in as User#1234</p>
</div>
A div is always displayed as a block element and thats the reason why it will start a new line below the div block. If you put the item as a part of the list tag then it should work. For example:
<div class="nav navbar-nav pull-md-right">
<ul class="nav navbar-nav">
<li class="nav-item">
<p class="navbar-text">Signed in as User#1234</p>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Sign In</a>
</li>
</ul>
</div>