Position navbar icons inline on mobile with Bootstrap 4? - html

I'm trying to configure a navbar in Bootstrap 4 to display additional icons to left the hamburger menu that only display on mobile.
I'm not able to get the icons to display inline and can't sort out where i am going wrong.
I add the classes navbar-nav to the list, d-lg-none to hide on larger devices. Are there built in classes in bootstrap that can fix the alignment of these? I can't even sort out where i am going wrong.
HTML:
<nav class="navbar navbar-expand-lg">
<div class="container">
<a class="navbar-brand" href="#">
<img src="assets/images/logo-blue-sm.png" alt="">
</a>
<ul class="navbar-nav d-lg-none ml-auto navbar-icons ">
<li class="nav-item">
<a class="nav-link" href="tel:+1234567890"><i class="fa fa-3x fa-map-marker"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="tel:+1234567890"><i class="fa fa-3x fa-comments"></i></a>
</li>
</ul>
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"> </span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="docMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Experience</a>
<ul class="dropdown-menu" aria-labelledby="docMenu">
<li> <a class="dropdown-item" href="#">Our Story</a> </li>
</ul>
</li>
</ul>
</div>
<div class="nav-item border-0 d-none d-lg-inline-block align-self-center">
Get Started
</div>
</div>
</div>
</nav>
Additional CSS:
.navbar-icons .nav-item{
border-bottom:none;
padding:0 5px;
position:relative;
}

Based on your layout you could easily solve that using bootstrap flex utility classes Read more.
Just add d-flex and flex-row classes to the ul that contains the items:
<ul class="navbar-nav d-lg-none ml-auto navbar-icons d-flex flex-row">
this will change the uls display to flex and force the flex direction to be row style, so the items will be displayed side by side.
here is a very good guide to flexbox. try understanding the basics and using it together with the bootstrap flex classes.

Related

There are extra indents in the navbar in bootstrap 5, how to remove them?

There was a problem with extra padding in the navbar after the site icon. Initially, the idea was to place links that are located to the left of the icon closer to the left edge using me-3, but then the icon of the site is shifted to the right, which I basically don’t need.Therefore, I have a question. Is it possible to make the same indents from the site icon and links without shifting this icon from the center or how to remove the indent between the icon and links on the right side of the navbar.
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="scroll">
<div class="container-fluid">
<div class="collapse navbar-collapse order-1 order-lg-0 dual-collapse2" id="navbarNavAltMarkup">
<ul class="navbar-nav ms-auto">
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#articles">기사들</a>
</li>
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#mission">우리의 임무</a>
</li>
</ul>
</div>
<a class="navbar-brand order-0" href="#">
<img src="img/marslogo.png" alt="" width="30" height="30">
</a>
<div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse order-3 dual-collapse2" id="navbarNavAltMarkup"
>
<ul class="navbar-nav">
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#">사진들</a>
</li>
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#">문의하기</a>
</li>
</ul>
</div>
</div>
</nav>

Issues with centered logo on smaller devices

I am having an issue with my centered logo on bootstrap navbar menu; I put the logo in the center of the navbar; it is working fine on desktop but when I resize the page to a smaller device, the logo, because of the presence of the Hamburger menu button on the right and its relatively pixels used, becomes out of center towards to the left.
How can I make sure that on devices with smaller screens the logo remains centered?
<nav class="navbar navbar-expand-xl navbar-toggleable-md navbar-light bg-white" id="nav1">
<div class="navbar-collapse collapse w-100 order-1 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item home">
<a class="nav-link" href="#">HOME <span class="sr-only">(current)</span> </li>
<li class="nav-item"> <a class="nav-link" href="#">OUR WEDDINGS </li>
</ul>
</div>
<div class="mx-auto order-0 order-xl-2">
<a class="navbar-brand mx-auto" href="/"><img src="Imagine/00 Top Logo 2021.png" alt="Logo 2021" width="275" height="127"></a></div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<li class="nav-item"> <a class="nav-link" href="#">LEGALITIES </li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
Foreword
Before we go into the solution, one thing to note is that if this solution is implemented and the window is not wide enough to fit both the logo and the toggler without overlapping, they will do just that -- overlap.
Solution
1. Styles
You can do that using transform and position: absolute:
.navbar-brand {
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
/* to place the toggler above the logo, in case they overlap */
.navbar-toggler: {
z-index: 10;
}
2. HTML
There are also some issues in the HTML. The big one is missing closing tags for <a class="nav-link">. See this jsfiddle version and check the HTML textarea for where the linter highlights issues. Also, the sr-only class is for screen readers so you want to include it for each link and make sure the text content matches the link itself -- see this answer for a great explanation of that.
Here's a refactored version of the HTML:
<nav class="navbar navbar-expand-xl navbar-toggleable-md navbar-light bg-white" id="nav1">
<div class="navbar-collapse collapse w-100 order-1 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item home">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/">
HOME
<span class="sr-only">Home</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/wedding_sicily_our_weddings.html">
OUR WEDDINGS
<span class="sr-only">Our Weddings</span>
</a>
</li>
</ul>
</div>
<div class="mx-auto order-0 order-xl-2 navbar-brand-container">
<a class="navbar-brand mx-auto" href="/">
<img src="Imagine/00 Top Logo 2021.png" alt="Logo 2021" width="275" height="127">
</a>
</div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/wedding_sicily_legalities.html">
LEGALITIES
<span class="sr-only">Legalities</span>
</a>
</li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
3. Demo
See this jsfiddle demo for the complete working solution.
Hope that helps!
Add position: absolute in .navbar-toggler. See if it helps you:
https://jsfiddle.net/omk9pg58/

navbar-brand image overlapping nav-items

I have the navbar below, but right now, when I open the page on the browser, the items inside ul class="navbar-nav mr-auto" are not displayed entirely because are placed behind the navbar-brand image. Anyone knows how to fix that?
<nav class="navbar navbar-expand-lg navbar-dark fixed-top bg-dark">
<a class="navbar-brand pr-3" href="#">
<img th:src="#{/img/banner.jpg}" class="d-inline-block align-top pl-3" alt="Kleber App Store">
</a>
<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 pl-3" id="navbar">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</nav>
css for this page
body {
min-height: 75rem;
padding-top: 4.5rem;
}
.navbar-brand img {
top: 0;
position: absolute;
}
You can modify the class and also you dont need position absolute on your CSS file. This action will adjust your image to your layout, trusting you are working with bootstrap, I have removed as well your th:src since it is not necessary as well, check this code below.
<img src="#{/img/banner.jpg}" class="d-inline-block align-top pl-3 img-fluid" alt="Kleber App Store">
By adding to your class img-fluid, your image will adjust to any screen or layout and fit only where it belongs, make sure that image is not that big too and remove the position from your CSS.

How to make a nav-item reach the end of the page

I am new to Bootstrap and web development but I am trying to reorganize the default navbar that is generated with the execution of a blank asp.net core 2.2 web application. When this web app is generated there are nav-items that are floated to the left, but in this navbar I want to add another nav-item for log in and place it all the way to the right of the page similar to how many websites place their login links.
I have tried playing around with margins and padding in the container as well as in the navbar. When I would change the margins for the left and right side of the container it would just shift the entire navbar in one direction either left or right. I have also opened up and looked at the bootstrap.css in order to see how it works and trying to see if I could find useful information. I have also tried playing around with the different nav-bar classes.
//I tried playing around with margins in my css as such
.container{
padding-left: 0px;
padding-right: 0px;
}
//part of my layout page
<header>
`<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light
bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-
page="/Index">RazorPagesDemo</a>
<button class="navbar-toggler" type="button" data-
toggle="collapse" data-target=".navbar-collapse" aria-
controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-
sm-row ">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-
page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-
page="/Privacy">Privacy</a>
</li>
</ul>
<ul class="navbar-nav flex">
<li>
<a class="nav-link text-dark" asp-area="" asp-
page="/Login">Login</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
Here I would like to make it so that my login nav-item reaches all the way to the right corner.
You could set style as position:absolute;right:0 to place it at the right of page:
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">RazorPagesDemo</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row ">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-
page="/Index">Home1</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-
page="/Privacy">Privacy1</a>
</li>
</ul>
<ul class="navbar-nav flex" style="position:absolute;right:0">
<li>
<a class="nav-link text-dark" asp-area="" asp-page="/Login">Login</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
As long as your navigation is inside .container it will be max-width: 1140px wide and centered because of margin-left: auto and margin-right: auto.
Try to use .container-fluid or remove container div so it will be full width "from left to right".

Boostrap 4 Navbar Collapse Menu Right Align

I am using Bootstrap 4 and I am trying to make the menu that pops up by clicking the collapse button to open on the right side instead of the left. I have tried using "ml-auto" on the "ul" element. The navbar items are correctly on the right side when it isn't collapsed. When it is collapsed, the button is correctly on the right side but the menu pops up on the left. I have also tried putting "ml-auto" in the div as well but that didn't work. Here is my HTML:
<nav class="navbar navbar-expand-lg navbar-dark fixed-top">
<a class="navbar-brand" href="#home"><img id="logo" class="no-opacity" src="content/white-logo.png"></a>
<button class="navbar-toggler ml-auto" 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 ml-auto">
<li class="nav-item">
<a class="nav-link" href="#home"><i class="fa fa-home fa-fw" aria-hidden="true"></i> Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about"><i class="fa fa-user fa-fw" aria-hidden="true"></i> About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#projects"><i class="fa fa-folder-open fa-fw" aria-hidden="true"></i> Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#experience"><i class="fa fa-briefcase fa-fw" aria-hidden="true"></i> Experience</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact"><i class="fa fa-envelope fa-fw" aria-hidden="true"></i> Contact</a>
</li>
</ul>
</div>
</nav>
I feel like there is a simple solution but I can't figure it out.
Just add simple rule to your css.
.nav-item{
text-align: right;
}
According to http://getbootstrap.com/docs/4.0/components/navs/#horizontal-alignment, the way to center, right-justify, or left-justify things in the navbar's collapsed dropdown is to use justify-content-end and friends in the class of a nav.
Example. This code yields the image following it.
<nav class="navbar navbar-expand-lg fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<ul class="list-inline social-buttons">
{% for link in site.social %}
<li class="list-inline-item">
<i class="{{ link.icon }}"></i>
</li>
{% endfor %}
</ul>
<div class="navbar-toggler" data-toggle="collapse" data-target="#menu">
☰<!-- three bars symbol -->
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="menu">
<ul class="nav ml-auto">
<a class="nav-link page-scroll" href="#about">About</a>
<a class="nav-link page-scroll" href="#projects">Projects</a>
<a class="nav-link page-scroll" href="#writing">Writing</a>
<a class="nav-link page-scroll" href="#contact">Contact</a>
</ul>
</div>
</div>
</nav>
Now amending that one line to:
<div class="nav ml-auto justify-content-end">
yields
Note this evidently has nothing to do with ml-auto, which when missing causes the uncollapsed menu items (on a wider screen) to not be right-justified. (The toggler button itself is always right justified for me.) Only justify seems to control the stuff in the uncollapsed menu.
Just use "text-right" in HTML
For example:
<div class="navbar-collapse text-right" id="navbarResponsive">