Putting more items in Bootstrap Navbar - css

I have a bootstrap navbar. I want to put signOut and welcome in the menu bar along with other menu items. Below is the screenshot of my navbar:
I want to put SignOut where the purple arrow is and right beneath "SignOut", I want to put "Welcome userName". I also want to move the logo and company/city name to extreeme left of the nav bar . How can I achieve that? Below is my code:
<nav class="navbar navbar-expand-lg py-5 navbar-dark shadow-sm " style="background-color: #264653;width:100%;" >
<div class="container">
<span class="navbar-brand" style="display:flex;">
<img src="~/Images/InfoOrange.png" alt="ACR" width="70" height="70" class="d-inline-block align-middle mr-2" runat="server" />
<span style="font-size:25px;color:white;"><span style="color:#e9c46a">test City</span><br />test company</span>
</span>
<button type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler"><span class="navbar-toggler-icon"></span></button>
<div id="navbarSupportedContent" class="collapse navbar-collapse">
<ul class="navbar-nav ml-auto">
<%-- <li class="nav-item active">Home <span class="sr-only">(current)</span></li>--%>
<li class="nav-item dropdown nav-item active">
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Users
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Details</a>
<a class="dropdown-item" href="Depatment.aspx">Department</a>
<%-- <a class="dropdown-item" href="#">Sections</a>--%>
</div>
</li>
<li> </li>
<li class="nav-item dropdown nav-item active">
<a class="nav-link dropdown-toggle" href="#" id="admindropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Admin
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="NewBoxFolder.aspx">Box/Folder</a>
<a class="dropdown-item" href="#">Configuration</a>
</div>
</li>
<li> </li>
<li class="nav-item dropdown nav-item active">
<a class="nav-link dropdown-toggle" href="#" id="recordsDropDown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Records
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="FileUpload.aspx">BlockChain Upload</a>
<a class="dropdown-item" href="#">Verify</a>
<a class="dropdown-item" href="DocReport.aspx">Report</a>
<a class="dropdown-item" href="BucketList.aspx">S3 List</a>
</div>
</li>
</div>
<div>
<ul>
<li class="nav-item" style="margin-right:5px" >
<a class="nav-link px-5" href="<%= ResolveUrl("~/Pages/SignOut.aspx") %>">Sign Out</a>
</li>
</ul>
</div>
</div>
</nav>

You can contain this section with a class. In this instance I called it <div class="sign">. Then since your ul is a direct child of the parent you can use .sign > ul in your CSS to target that div. To get it in that position you can simply apply absolute positioning which allows you to define the area of the page. In your application, the top right. You can then add in your Welcome & Username area underneath as other unordered list items.
.sign > ul {
position: absolute;
top: 0;
right: 0;
list-style-type: none;
}
<div class="sign">
<ul>
<li class="nav-item" style="margin-right:5px" >
<a class="nav-link px-5" href="<%= ResolveUrl("~/Pages/SignOut.aspx") %>">Sign Out</a>
</li>
</ul>
</div>

Related

Bootstrap 4 Dropdown Menu appears to the right of parent

I'm newer to Bootstrap and have a question about my Navbar.
Here is my test site. TEST-DOMAIN
I'm currently using Bootstrap 4.3.1 with JQuery 3.4.1.
Menu looks and functions great on Desktop. Dropdown appears as expected. I added columns to the dropdown to make a Mega Menu of sorts.
When the site transitions over to mobile, the dropdown is appearing to the RIGHT of the parent menu item. Is there a way to make it appear BELOW the parent item and push the rest of the menu down below it?
I tried setting the dropdown to Display: absolute as found in other posts about this. But, while it shifts the dropdown to the left like I want, it floats it overtop of the rest of the menu. I would like it to align left, while pushing the rest of the menu below it.
Thanks for any help!
* EDIT - Adding code *
<!--Navbar-->
<nav id="navbar" class="navbar navbar-expand-lg navbar-dark nav-transparent sticky-top">
<div class="container">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#" style="margin-top: -5px;"><strong>Test Website</strong></a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-center">
<li class="nav-item active">
<a class="nav-link" href="home.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown btn-group">
<a class="nav-link dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Services</a>
<div class="dropdown-menu dropdown" aria-labelledby="dropdownMenu1">
<div class="container">
<div class="row">
<div class="col-md-4">
<a class="dropdown-item" href="another-page.html">ANOTHER PAGE</a>
<a class="dropdown-item" href="pools.html">POOLS</a>
<a class="dropdown-item" href="test-10.html">TEST 10</a>
<a class="dropdown-item" href="test-5.html">TEST 5</a>
</div>
<div class="col-md-4">
<a class="dropdown-item" href="test-6.html">TEST 6</a>
<a class="dropdown-item" href="test-7.html">TEST 7</a>
<a class="dropdown-item" href="test-8.html">TEST 8</a>
<a class="dropdown-item" href="test-9.html">TEST 9</a>
</div>
<div class="col-md-4">
<a class="dropdown-item" href="yet-another-page.html">YET ANOTHER PAGE</a>
<a class="dropdown-item" href="awesome-page.html">AWESOME PAGE</a>
</div>
</div>
</div>
</div>
</li>
<li class="nav-item"><a class="nav-link" href="about.html">About Us</a></li>
<li class="nav-item"><a class="nav-link" href="gallery.html">Gallery</a></li>
<li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li>
<li class="nav-item"><a class="nav-link" href="kitchen-vision.html">KITCHEN VISION</a></li>
<li class="nav-item"><a class="nav-link" href="contact.html">Contact Us</a>
</li>
</ul>
</div>
</div>
I've removed all my custom CSS for the NavBar to make sure I wasn't doing something incorrect with my edits.
#media screen and (max-width: 768px) {
.mx-auto.d-flex {
margin: 0!important;
justify-content: space-between;
display: flex;
width: 100vw;
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="mx-auto d-flex">
<a class="navbar-brand" href="#">Test Website</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Services
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<div class="container">
<div class="row">
<div class="col-md-4">
<a class="dropdown-item" href="another-page.html">ANOTHER PAGE</a>
<a class="dropdown-item" href="pools.html">POOLS</a>
<a class="dropdown-item" href="test-10.html">TEST 10</a>
<a class="dropdown-item" href="test-5.html">TEST 5</a>
</div>
<div class="col-md-4">
<a class="dropdown-item" href="test-6.html">TEST 6</a>
<a class="dropdown-item" href="test-7.html">TEST 7</a>
<a class="dropdown-item" href="test-8.html">TEST 8</a>
<a class="dropdown-item" href="test-9.html">TEST 9</a>
</div>
<div class="col-md-4">
<a class="dropdown-item" href="yet-another-page.html">YET ANOTHER PAGE</a>
<a class="dropdown-item" href="awesome-page.html">AWESOME PAGE</a>
</div>
</div>
</div>
</div>
</li>
<li class="nav-item"><a class="nav-link" href="about.html">About Us</a></li>
<li class="nav-item"><a class="nav-link" href="gallery.html">Gallery</a></li>
<li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li>
<li class="nav-item"><a class="nav-link" href="kitchen-vision.html">KITCHEN VISION</a></li>
<li class="nav-item"><a class="nav-link" href="contact.html">Contact Us</a>
</li>
</ul>
</div>
</div>
</nav>

Move items inside the BOOSTRAP navigation bar

I want to move the first item of the list (logo) to the left, to separate it from the rest of the items. I want it to remain responsive and that the distance from the left margin to the logo is always the same as from the right margin to the last item. Any ideas? I share my code.
Please help!
<nav class="navbar navbar-expand-md sticky-top">
<div class="nav-item-logo-vista-reducida">
<a class="nav-link" href="index.html"><img src="static/img/logo.png" class="logo-premoldeados"></a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"><img src="static/img/hamb-menu.png" class="hamb-menu" alt="Menú"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav mx-auto text-center">
<li class="nav-item-logo">
<a class="nav-link" href="index.html"><img src="static/img/logo.png" class="logo-premoldeados"></a>
</li>
<li class="nav-item">
<a class="nav-link nav-link-con-hover" href="atermicos.html">Atérmicos</a>
</li>
<li class="nav-item">
<a class="nav-link nav-link-con-hover" href="pisos-y-revestimientos.html">Pisos & Revestimientos</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link nav-link-con-hover" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Mobiliario Urbano
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item nav-link-con-hover" href="bancos.html">Bancos</a>
<a class="dropdown-item nav-link-con-hover" href="cestos.html">Cestos</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link nav-link-con-hover" href="nosotros.html">Nosotros</a>
</li>
<li class="nav-item">
<a class="nav-link nav-link-con-hover" href="contacto.html">Contacto</a>
</li>
</ul>
</div>
</nav>
Wrap your logo into separate logo-parent div and navigation ul in another nav-parent div then wrap this logo-parent and nav-parent into super-parent div. Then set the padding of the super-parent and set display: flex; flex-direction: row; this will align the logo and and nav list side by side and then set margin-left: auto of nav-parent div.

Prevent dropdown list in collapsed bootstrap4 navbar from expanding the navbar

I needed a selector that doesn't collapse alongside the rest of the menu in a bootstrap v4 navbar. Got something working, too. See below.
It's a bit hacky as there are actually two language selectors, but one is hidden when the browser window is smaller than the lg-breakpoint in bootstrap. Opposite way round if it is larger than the lg-breakpoint obviously. It works fine - but there might be a more elegant way to do this.
What I don't like is that, when the nav collapses, clicking on the language selector expands the navbar by the height of the dropdown list. Obviously it has to as the language selector is wrapped in the collabsed "nav" - but I'd much rather it'd behave as it does with the lg and wider selector - there the dropdown extends beyond the navbar without changing the size of the navbar.
Is there any way around this?
See these images:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<!--navigation-->
<nav class="navbar sticky-top navbar-dark navbar-expand-lg">
<a class="navbar-brand" href="#">Page Title</a>
<!--language selector for collapsed menu [hidden when viewport larger than medium]-->
<div class="d-lg-none ml-auto">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">🌐 Language</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Language 1</a>
<a class="dropdown-item" href="#">Language 2</a>
<a class="dropdown-item" href="#">Language 3</a>
</div>
</li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar">
<div class="navbar-nav">
<!-- page user is looking at = "nav-link active"-->
<a class="nav-item nav-link active" href="#">Home<span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">Link 1</a>
<a class="nav-item nav-link" href="#">Link 2</a>
<div class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">The Team</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Link</a>
<a class="dropdown-item" href="#">Another Link</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">An entirely different link</a>
</div>
</div>
<a class="nav-item nav-link" href="sponsor_us.php">Link 3</a>
<a class="nav-item nav-link disabled" href="#">inactive Link</a>
</div>
</div>
<!--language selector for expanded menu [hidden viewport size medium and down]-->
<div class="d-none d-sm-none d-md-none d-lg-block d-xl-block ml-auto">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">🌐 Language</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Language 1</a>
<a class="dropdown-item" href="#">Language 2</a>
<a class="dropdown-item" href="#">Language 3</a>
</div>
</li>
</ul>
</div>
</nav>
Edit: Here's a jsfiddle link - albeit for some reason that one doesn't use the bootstrap.css file I'd added in the resources. So the menu is white, not black :). You have to change the width of the window that displays the html to see the menu expanding and collapsing.
I know this is old, but this was the ONLY place I'd found this question asked.
Simple way:
css: .popout { position: absolute !important;}
now add popout class to you div that you no longer want to remain inside the navbar while the navbar is collapsed!
<style>
.popout { position: absolute !important;}
</style>
<html>
...
<div class="dropdown-menu dropdown-menu-right popout" ...>
<a class="dropdown-item" href="#">Language 1</a>
<a class="dropdown-item" href="#">Language 2</a>
<a class="dropdown-item" href="#">Language 3</a>
</div>
</html>

How to remove the space between navbar toggle menu collapse and header

I'm using Bootstrap v4.0 for my site, and I have made a basic navbar which goes like this
(Codepen link).
And the problem with this menu is that, when you minimize the page to see how this nav works in md and sm devices, it shows a space between the navbar and the header:
see this image
So my question is, how to remove this space?
Here is the html code:
<nav class="navbar navbar-expand-lg navbar-custom BKoodakBold">
<img id="img1" class="hidden-xs" src="img/letter-logo.png" width="100" height="100"></img><script>rotateAnimation("img1",30);</script><img id="img2" src="img/text-logo.png" width="300" height="100"></img>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbarMd">
<i class="fa fa-bars fa-lg py-1 text-white"></i>
</button>
<div class="navbar-collapse collapse" id="collapsingNavbarMd">
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
فروشگاه
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">ویژه</a>
<a class="dropdown-item" href="#">پایین ترین قیمت ها</a>
<a class="dropdown-item" href="#">مرور کردن</a>
<a class="dropdown-item" href="#">ساخت سلاح</a>
<a class="dropdown-item" href="#">پوشاک</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">تجارت</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
راهنما
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">پرسش و پاسخ</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
جامعه
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">وبلاگ</a>
<a class="dropdown-item" href="#">کاتالوگ</a>
<a class="dropdown-item" href="#">درباره</a>
<a class="dropdown-item" href="#">لیست قیمت</a>
<!-- <a class="dropdown-item" href="#">API Documentation</a>
<a class="dropdown-item" href="#">npm package</a> -->
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">مالی</a>
</li>
<button class="btn BJadidBold">ورود/ عضویت</button>
</ul>
</div>
</nav>
I have searched the forum to find a related problem, but I couldn't find anything useful. So it would be best if you can help me with that..
Thanks in advance :)
This space is the overflow of .navbar-custom.
You have to change the height:100px; to auto in media query.
#media only screen and (max-width: 992px) {
.navbar-custom {
height:auto;
}
}
Note:Place media query to bottom of your normal css. In codepen its on
top.

How to move elements (home,features,pricing, dropdown linbaak) to the right side of navbar?

<div class="container">
<nav class="navbar navbar-toggleable-lg fixed-top navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse ">
<ul class="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="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
</div>
I want to pull-right home, features, pricing, and dropdown link elements.
I was trying to add to ul class="pull-right" but its not working.
I also tried to add nabar-right class to ul section also nothing.
From the bootstrap documentation:
Align nav links, forms, buttons, or text, using the .navbar-left or
.navbar-right utility classes. Both classes will add a CSS float in
the specified direction. For example, to align nav links, put them in
a separate <ul> with the respective utility class applied.
So use the .navbar-right class on your <ul>
Example: https://jsfiddle.net/1s7j8srp/

Resources