Bootstrap - Nav bar not working correctly - html

In my project, I implement bootstrap. I also make use of the full navbar that bootstrap provides. I set a custom colour and height to this navbar. When making the browser window smaller, the hamburger icon appears as expected.
When pressing the hamburger icon, none of the menu items appear. I discover that if I make my navbar larger in height, the menu items appear below. However I want the navbar to stay the height it currently is.
Does Anybody know how to move the menu items, maybe to the right to allow them to be seen when the hamburger icon is pressed? This is of course without changing the height of the navbar. Thank you.
Here is my existing code:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<!-- <a class="navbar-brand" href="#">Navbar</a> -->
<div class="imageDiv">
<img class="navbar-brand barberImg" src="{% static 'icon.png' %}" width="63px" alt="Image of man getting haircut">
</div>
<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 mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#" style="color: white; margin-left: 100px;">Home <span class="sr-only">(current)</span></a>
</ul>
</div>
</nav>
.navbar{
background-image: none;
background-color: #191919 !important;
height: 4.9em;
}
.imageDiv {
background-color: #CED0CE;
width: 98px;
height: 80px;
position: relative;
margin-top: -1px;
margin-left: -16px;
}
.barberImg {
position: relative;
bottom: 6px;
left: 15px;
}
#media screen and (max-width: 991px) {
.imageDiv {
position: relative;
bottom: 8px;
}
}

Related

Navbar items don't stay fixed when I open the overflow-toggler

Preface - I am not asking about "navbar-fixed-top"
I am trying to make simple Navbar with a custom height.
HTML code:
<nav class="navbar navbar-expand-md">
<div class="container-fluid nav-bar">
<a class="navbar-brand" href="#">Navbar</a>
<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">H</span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav ms-auto">
<a class="nav-link" href="#">HOME</a>
<a class="nav-link" href="#">DESTINATIONS</a>
<a class="nav-link" href="#">CREW</a>
<a class="nav-link" href="#">TECHNOLOGIES</a>
</div>
</div>
</div>
</nav>
CSS code:
.navbar {
background-color: orange;
height: 72px !important;
}
a {
color: #000;
}
Here's the Codeply link: https://www.codeply.com/p/mBsxyw02Q3
When opening the Overflow menu (or toggler in Bootstrap language) - the 'Nav-brand' along with other elements in the Navigation bar displace upwards to show the hidden elements.
Something about me - I just started out Web Dev, so I just know a handful of things about HTML and CSS. I understand that the issue here maybe happening because of script, but I am not sure. So let me know if this issue can be corrected with CSS and how. If not, is it related to javascript?
I have inspected the page for any changes in padding or margin when I open the hamburger menu, but there's no changes so I am kind of out of idea what might be happening here.
You need add few lines of code to resolve this issue.
.navigation {
background-color: orange;
min-height: 72px !important;
}
.navbar-brand {
min-height: 55px;
line-height: 48px;;
}

Navbar logo won't appear (bootstrap/django)

Hello I'm trying to add a logo to my navbar but it won't show up. I've looked at other's questions on this matter but I still can't make it show up.
I'm not sure whether the problem is with my code or my image.
I have added the image into the same directory as my code.
My code is as below
.navbar li a {
background-image: "/app/static/app/images/logoa.png";
}
.search {
list-style: none;
padding: 0;
width: fit-content;
border: 0px;
/*border added to visualise collision box*/
}
.search-bar {
display: none;
}
.search-icon {
width: fit-content;
border: 0px;
/*border added to visualise collision box*/
}
.search-icon:hover+.search-bar {
display: block;
}
.search-bar:hover {
display: block;
}
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<img src="/app/templates/logoa.png" alt="computer display with dna in it" width="30" height="24" class="d-inline-block align-text-top">
<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 class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-link active" aria-current="page" href="#">homepage</a>
<a class="nav-link" href="#">form</a>
<a class="nav-link disabled" href="#">workflow</a>
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">tools</a>
</div>
<ul class="search">
<li class="search-icon"><i class="fas fa-search" style="position:absolute; right:10px;"></i></li>
<li class="search-bar" style="position:absolute; right:10px;"><input placeholder="enter search" action=""></li>
</ul>
</div>
</div>
</nav>
edit;;
if i try to follow the path i set in the code it leads me to the image (in visual studio code)
but it can't find it in the browser console
help.png:1 Failed to load resource: the server responded with a >status of 404 (Not Found)
I had the same issue. What worked for me was removing the extension that I was using for the image (.svg) and let Visual Studio code suggest/pick the right extension/path (.jpg).
I had a similar issue. In the .html page, instead of: <img src="/app/templates/logoa.png" try rendering the image with this path instead: <img src="{% static 'app/templates/logoa.png' %}" This syntax is more "Django friendly". Hope this helps.

Central logo that overlaps navbar bootstrap [duplicate]

This question already has answers here:
Bootstrap NavBar with left, center or right aligned items
(14 answers)
Closed 1 year ago.
Hi I am trying to get my navbar to look like this:
But I cant seem to figure out how to get the image to be on top of the navbar. I am using bootsrap 5. I havent added any css to the navbar yet is there some property i can use to bring it to the front. Thanks, here is the html:
<header>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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 me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ABOUT</a>
</li>
<a class="navbar-brand" href="#"><img src="/images/logos/circle-cropped.png" alt=""></a>
<!-- <img src="/images/logos/circle-cropped.png"> -->
</ul>
</div>
</div>
</nav>
</header>
WORKING DEMO HERE
This CSS should help:
.navbar-brand {
flex: 0 1 auto;
display: block;
width: 100px;
height: 100px;
position: absolute;
left: 50%;
top: 0;
margin: 0 !important;
padding: 0 !important;
transform: translateX(-50%);
text-align: center;
}
.navbar-brand img {
max-height: 100%;
max-width: 100%;
}

Bootstrap 4: HTML - Using a Div with the Navbar

In my project, I have implemented bootstrap in order to create a navbar. This works successfully, and the navbar is fully responsive.
When the screen reaches a certain size, the hamburger icon appears which allows users to select navbar options.
After a user presses the hamburger icon, I want a little box/div to appear directly below. I have performed a media query so that the box does not appear when the hamburger icon disappears.
However what I want to implement is that when the user rescales the window, I want the div box to move along with the hamburger icon.
Here is my existing code:
<nav style="height: 80px;" class="navbar navbar-expand-lg navbar-dark bg-dark">
<img src="{% static 'myicon.png' %}" style="margin-left: -15px;" width="99px" height="91px" class="navbar-brand bIcon" alt="Image of scissors and comb">
<div class="navbar-brand" style="width: 1px; left: 100px; bottom: 1px; position: absolute; height: 77px; border: 1px solid #454545;"></div>
<span class="navbar-brand" style="position: absolute; top: 16px; left: 125px; font-size: 26px; letter-spacing: 1px;" >Test</span>
<button style="margin-top: -16px;" 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">
// HERE IS THE DIV/BOX I AM TALKING ABOUT =>
<div class="collapseBox" style="width: 100px; margin-left: 100px; height: 100px; border: 1px solid white;"></div>
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Sign Up <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
Does anybody know how to implement this functionality?
Thank you.
A few things I did:
your navigation has the class navbar-expand-lg which means that burger menu disappears on sizes lg and above... so we assigned the class d-lg-none to our div collapseBox
you wanted this div directly under the burger menu, so we get position:absolute for this
next, the burger menu has a margin of 16px to its right (due to margin on the nav element), so we move our div to the right by 16px;
the height of the nav is 80px, so we move our div down by 80px also
working snippet below:
.collapseBox {
width: 100px;
margin-left: 100px;
height: 100px;
background-color: pink;
border: 1px solid red;
position: absolute;
right;
right: 16px;
top: 80px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<nav style="height: 80px;" class="navbar navbar-expand-lg navbar-dark bg-dark">
<img src="{% static 'myicon.png' %}" style="margin-left: -15px;" width="99px" height="91px" class="navbar-brand bIcon" alt="Image of scissors and comb">
<div class="navbar-brand" style="width: 1px; left: 100px; bottom: 1px; position: absolute; height: 77px; border: 1px solid #454545;"></div>
<span class="navbar-brand" style="position: absolute; top: 16px; left: 125px; font-size: 26px; letter-spacing: 1px;">Test</span>
<button style="margin-top: -16px;" 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">
// HERE IS THE DIV/BOX I AM TALKING ABOUT =>
<div class="collapseBox d-lg-none"></div>
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Sign Up <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>

ASP Net Core Angular - Default Project with bootstrap 4 instead of 3 (SideMenu)

I am trying to build a website with Angular6 where there is a vertical navbar when viewed on a large screen and a top navbar with a dropdown on mobile. With Bootstrap 4. I have found multiple examples online but they all seems overly complicated or build without the nav template.
The example project from ASP.Net Core with Angular have a navbar like I want but it is written with Bootstrap3. I have tried to convert it without success and this is where I ask for your help!
Original Code with Bootstrap 3. If you have dotnet core installed, you can use dotnet new angular -o my-new-app to create the project.
HTML
<div class='main-nav'>
<div class='navbar navbar-inverse'>
<div class='navbar-header'>
<button type='button' class='navbar-toggle' data-toggle='collapse' data-target='.navbar-collapse' [attr.aria-expanded]='isExpanded' (click)='toggle()'>
<span class='sr-only'>Toggle navigation</span>
<span class='icon-bar'></span>
<span class='icon-bar'></span>
<span class='icon-bar'></span>
</button>
<a class='navbar-brand' [routerLink]='["/"]'>my_new_app</a>
</div>
<div class='clearfix'></div>
<div class='navbar-collapse collapse' [ngClass]='{ "in": isExpanded }'>
<ul class='nav navbar-nav'>
<li [routerLinkActive]='["link-active"]' [routerLinkActiveOptions]='{ exact: true }'>
<a [routerLink]='["/"]' (click)='collapse()'>
<span class='glyphicon glyphicon-home'></span> Home
</a>
</li>
<li [routerLinkActive]='["link-active"]'>
<a [routerLink]='["/counter"]' (click)='collapse()'>
<span class='glyphicon glyphicon-education'></span> Counter
</a>
</li>
<li [routerLinkActive]='["link-active"]'>
<a [routerLink]='["/fetch-data"]' (click)='collapse()'>
<span class='glyphicon glyphicon-th-list'></span> Fetch data
</a>
</li>
</ul>
</div>
</div>
CSS
li .glyphicon {
margin-right: 10px;
}
/* Highlighting rules for nav menu items */
li.link-active a,
li.link-active a:hover,
li.link-active a:focus {
background-color: #4189C7;
color: white;
}
/* Keep the nav menu independent of scrolling and on top of other items */
.main-nav {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1;
}
#media (min-width: 768px) {
/* On small screens, convert the nav menu to a vertical sidebar */
.main-nav {
height: 100%;
width: calc(25% - 20px);
}
.navbar {
border-radius: 0px;
border-width: 0px;
height: 100%;
}
.navbar-header {
float: none;
}
.navbar-collapse {
border-top: 1px solid #444;
padding: 0px;
}
.navbar ul {
float: none;
}
.navbar li {
float: none;
font-size: 15px;
margin: 6px;
}
.navbar li a {
padding: 10px 16px;
border-radius: 4px;
}
.navbar a {
/* If a menu item's text is too long, truncate it */
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
And here is my attempt to convert it. I used the Bootstrap 4 documentation for the template
<div class="main-nav">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse" id="navbarNavAltMarkup">
<div class="nav flex-column">
<a class="nav-item nav-link active" href="#">Home</a>
<a class="nav-item nav-link" href="#">Features</a>
<a class="nav-item nav-link" href="#">Pricing</a>
<a class="nav-item nav-link disabled" href="#">Disabled</a>
</div>
</div>
</nav>
</div>
The problem is that the title and the nav are on the same line instead of having then on separate line. How could I achieve that?
(The mobile view doesn't seem to work either, but I haven't tried yet. I am trying to make the desktop view work first)
Looks like I didn't search long enough. I found the solution here: http://www.codingflow.net/building-single-page-applications-on-asp-net-core-2-1-with-angular-6-part-2-upgrading-to-bootstrap-4/
One of the key changes was this in the css
.flex-column {
width: 100%;
}