navbar-brand image overlapping nav-items - html

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.

Related

How to only get one li in your bootstrap navbar to move to the right

I am learning how to code with html and am trying to create a navbar to have some li on the right side and some on the left. Using bootstrap I can seem to find out how to move contact and only contact to the right side of my navbar. Does anyone know how to do that? I tried looking at other answers on this site and cant figure it out. Would I have to make the last one its own ul?
I have tried using float right and justify content end but it only works in the ul class and moves everything over. Same with ms-auto. If I put it down in the li class nothing changes. I have tried adding padding too but nothing moves. I just want to know how to move contact to the right side of my navbar and thats it not the About, My Account, and Login. Please ignore my html file names I know I have to update them.
Here is my code:
` <nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="images/circle_r.png" width="30" height="30" alt="">
</a>
<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"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home </span></a>
</li>
<li class="nav-item float-left">
<a class="nav-link" href="tenant.html">Login/Sign-Up</a>
</li>
<li class="nav-item">
<a class="nav-link" href="proprietor.html">My Account</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.html">Contact</a>
</li>
</ul>
</div>
</nav>`
You can move the "Contact" link to the right side of the navbar by adding a class to the ul element and using CSS to align the elements. Here's one way to do it:
Add a class to the ul element, for example: . The ml-auto class is from Bootstrap and will align the elements to the right.
Add a CSS rule to your stylesheet to change the justify-content property of the class you added to the ul element. For example:
.ml-auto {
justify-content: flex-end;
}
Your updated code would look like this:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="images/circle_r.png" width="30" height="30" alt="">
</a>
<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"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home </span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="tenant.html">Login/Sign-Up</a>
</li>
<li class="nav-item">
<a class="nav-link" href="proprietor.html">My Account</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.html">Contact</a>
</li>
</ul>
</div>
</nav>
You can apply position: absolute; to move the element to the right side of the navbar. I added a class contact to the li element so that css can be applied. Give the parent position: relative; as that will be the container the contact li is being responsive to. You can ignore the flex css as that was mainly for me to quickly align the links in a row. You can adjust the padding and spacing as needed.
.navbar-nav {
display: flex;
gap: 2rem;
background: lightgrey;
position: relative;
}
.nav-item {
list-style-type: none;
}
.contact {
position: absolute;
right: 0;
top: 0;
padding-right: 1rem;
}
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home </span></a>
</li>
<li class="nav-item float-left">
<a class="nav-link" href="tenant.html">Login/Sign-Up</a>
</li>
<li class="nav-item">
<a class="nav-link" href="proprietor.html">My Account</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
<li class="nav-item contact">
<a class="nav-link" href="contact.html">Contact</a>
</li>
</ul>

How can I change color of collapse menu?

I am trying to learn Bootstrap. I took the example navbar from the documentation, which is:
<nav class="navbar navbar-expand-lg navbar-light bg-primary">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<div>
<ul class="navbar-nav">
<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="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
Then I added this to my CSS file:
.navbar-collapse {
background-color: #fff;
}
However, the width of the collapse menu isn't 100% of the screen so the left and right side of the collapse menu do not change when I do this. I can remove the padding of the whole navbar but that messes up everything and I feel like there should be an easier way to do this. Is there really or should I just suck it up and adjust everything separately after removing the padding?
The easiest way would be to add a negative margin and then counteract with padding...
.navbar-collapse {
background-color: #fff;
margin-left: -15px;
margin-right: -15px;
padding-left: 15px;
padding-right: 15px;
}
Demo

Absolute positioning a bootstrap navbar interferes with alignment of items

I am trying to create a navbar overtop a carousel. The navbar should have two sets of links;
1: Links aligned to the left
2: Social media links aligned to the right
I have have done this successfully with the code below;
HTML
<nav class="navbar navbar-expand-lg navbar-light bg-light" id = "navigation">
<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="#">GALLERIES <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ABOUT</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="navbar-brand" href="#">
<img src="images/icons/shopping-cart.png" class = "nav_icon" alt = "">
</a>
</li>
<li class="nav-item">
<a class="navbar-brand" href="#">
<img src="images/icons/twitter.png" class = "nav_icon" alt = "">
</a>
</li>
</ul>
</div>
</nav>
CSS
#navigation{
z-index: 999;
background:0 !important;
font-size: 1.5vw;
color: #fff !important;
/*position: absolute;*/
}
.nav_icon{
width: 2vw;
height: 2vw;
}
This yields the following result;
However, I want the navbar to be overtop my carousel (code for the carousel not included).
Adding 'position: absolute' interferes with my alignment like so;
Why is this happening? How can I get the same results without messing up the alignment of the links?

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".

How can I put the Image in the top-left corner, while still being responsive?

I am new to Angular/Bootstrap and currently trying to put an image on top of the navigation bar in the top left corner. Using padding/margin could fix the problem with a normal resolution/static screen size, changing the size put the image elsewhere.
I have tried to use padding and margin, but as I said, it was not possible, to make it "sticky" in the top left corner, when changing the browser sice.
Also using the bootstrap classes, for example "pull-right" (just for test-cases) did not work.
My current code looks like:
<header>
<div class="cloud">
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark $green static-top">
<div class="container">
<a class="navbar-brand" href="#">
<img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.svg?v=a010291124bf" class="pull-right" alt="" width="431.27" height="55.35">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive"
aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<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="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Impressum</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
<div class="first">
<h1>TestSite</h1>
</div>
</header>
I expected an image in the top left corner that is responsively staying there while changing browsersizes/devices
Please check this code to see, whether this is the desired result. Fully working demo is available here
Main Changes made on your code is.
added CSS class bg-dark and removed $green static-top on nav. <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
fixed the width of brand image to 50%, using css. This can be changed to some other value.
removed width and height attributes from img tag.
.navbar-brand img{
width: 50%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">
<img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.svg?v=a010291124bf">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive"
aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<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="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Impressum</a>
</li>
</ul>
</div>
</div>
</nav>
</div>