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>
Related
This is my navigation bar (uses Bootstrap 4):
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<nav class="navbar navbar-expand-lg navbar-light bg-light rounded-bottom" style="height: 60px;">
<a class="navbar-brand text-blue font-weight-bold nav-link">Car Shop</a>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
Cars
Engine
<button type="submit" class="btn" name="create" style="background-color: #ffec00!important; position: absolute; margin-right: 0px; right: 15px; top: 11px;">Log Out</button>
</div>
</div>
</nav>
So except the main title Cars Shop, there are three more items:
Cars (aligned from the left)
Engine (aligned from the left)
Log Out button (in the top right corner)
On desktop it looks good, but when I switch to mobile (or resize window appropriately), the three items disappear completely. Is there any way to make this navbar a bit more user friendly?
As far ad I understand the problem is that you are using a collapsed navbar without the ability to open it after it collapses. I fixed it like this for a collapsed menu (you will need to change up your style a bit to make it look good):
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<nav class="navbar navbar-expand-lg navbar-light bg-light rounded-bottom" style="height: 60px;">
<a class="navbar-brand text-blue font-weight-bold nav-link">Car Shop</a>
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<i class="fa fa-angle-double-down"></i>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="navbar-collapse collapse" id="navbarSupportedContent">
Cars
Engine
<button type="submit" class="btn" name="create" style="background-color: #ffec00!important; position: absolute; margin-right: 3em; right: 15px; top: 11px;">Log Out</button>
</div>
</div>
</nav>
I would also recommend doing the CSS in a separate file if you aren't already and maybe try to use em, vh, vw instead of px.
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%;
}
I'm using Bootstrap for my navigation bar, and somehow I keep getting whitespace on the right side of the logo image. My navigation code looks like this:
.navbar {
background-color: white;
opacity: 80%;
font-size: 0.8em;
}
.nav-link a {
color: black;
}
.nav-item img {
width: 110px;
margin-top: 8px;
margin-left: 10px;
margin-right: 20px;
}
.nav-item a {
color: black;
}
.navButtons {
background-color: white;
color: black;
padding: 6px;
font-size: 12px;
}
.navButtons:hover {
color: black;
text-decoration: none;
}
<style>
<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">
</style>
<nav class="navbar fixed-top navbar-expand-sm navbar-light">
<a class="navbar-brand" href="index.html" style="margin:0;">
<img src="https://via.placeholder.com/468x60?text=Visit+Blogging.com+Now" alt="logo" style="width: 50%;">
</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="navbar-collapse collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="button navButtons" href="about.html"> Biography <span class="sr-only">(current)</span> </a>
</li>
<li class="nav-item">
<a class="button navButtons" href="interiorDesigns.html"> Interior Design </a>
</li>
<li class="nav-item">
<a class="button navButtons" href="arts.html"> Arts </a>
</li>
<li class="nav-item">
<a class="button navButtons" href="blogs.html"> Blogs </a>
</li>
<li class="nav-item">
<a class="button navButtons" href="contact.html"> Contact </a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<div class="form-group mb-4">
<input type="search" placeholder="Search" class="form-control form-control-underlined">
</div>
</form>
</div>
</nav>
And this is what my logo looks like, the yellow part is where I want to get rid of. I tried changing the padding, margin, and width, but none worked.:
In your Example the Anchor tag is is a block element/parent container of the image.
Apply width and padding-right(if required) to the navbar-brand.
Then instead of adding 50% width make it 100% to the img tag inside.
This will fix your issue.
Example Code (last two lines) in CSS then tag:
.navbar-brand {
display: inline-block;
padding-top: .3125rem;
padding-bottom: .3125rem;
margin-right: 1rem;
font-size: 1.25rem;
line-height: inherit;
white-space: nowrap;
width: 300px;
padding-right: 50px;
}
<img src="https://via.placeholder.com/468x60?text=Visit+Blogging.com+Now" alt="logo" style="width: 100%;">
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;
}
}
I am trying to position my content under my navbar and when I add the padding-top: 60px; it works but pushes the navbar down. I also need the background to be at the top of the page behind the navbar. How can I fix this? The content for the page including the navbar AND background are pushed down but I need the navbar and the background at the top of the page and only the content pushed down.
body {
padding-top: 65px;
margin: 0;
width: 100%;
}
#header {
background-color: grey;
opacity: .7;
width: 100%;
height: 80px;
position: fixed;
z-index: 1000;
}
#logo a {
font-size: 30px;
font-weight: bold;
color: rgb(255, 255, 255);
font-family: 'DIN 1451 Std Engschrift';
margin-top: 5px;
}
#slide1 {
width: 100%;
background: url('sunrise.png') 50% 0 no-repeat fixed;
background-size: cover;
color: #ffffff;
height: 700px;
margin: 0;
padding: 40px 0 260px 0;
}
.content {
margin: 0 auto;
width: 1000px;
}
<div id="header">
<div class="content">
<nav id="nav" class="navbar navbar-expand-lg">
<div id="logo">
<a class="navbar-brand" href="#">Navbar Logo</a>
</div>
<button class="navbar-toggler" 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>
<div id="logo">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<a class="nav-item nav-link" href="#slide3">How it Works</a>
<a class="nav-item nav-link" href="#slide4">For Landlords</a>
<a class="nav-item nav-link" href="#">F.A.Q</a>
<a class="nav-item nav-link" href="#pricingslide">Pricing</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
<body>
<div id="slide1">
<div class="content">
<h1 id="headline">Use Your Rent To Buy A Home</h1>
<p id="subtitle">Build a credit history, create a down payment,<br> all by just making rent payments thru LikeHome</p>
<h3>Find out how soon you can become a homeowner?</h3>
<%= render '_how_much_buying_form.html.erb' %>
</div>
</div>
</body>
</html>
Do this work for you?
body {
margin: 0;
width: 100%;
}
#slide1 {
background: url('http://res.cloudinary.com/sayob/image/upload/v1526907328/483257_vwhhfw.jpg') 50% 0 no-repeat fixed;
background-size: cover;
color: #ffffff;
height: 700px;
padding: 40px;
margin-top: 20px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<nav id="nav" class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div id="logo">
<a class="navbar-brand" href="#">Navbar Logo</a>
</div>
<button class="navbar-toggler" 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>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#slide3">How it Works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#slide4">For Landlords</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">F.A.Q</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#pricingslide">Pricing</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid" id="slide1">
<h1 id="headline">Use Your Rent To Buy A Home</h1>
<p id="subtitle">Build a credit history, create a down payment,<br> all by just making rent payments thru LikeHome</p>
<h3>Find out how soon you can become a homeowner?</h3>
</div>
First of all you need to correct the HTML markups. All html contents must be inside tag. Wrap the elements in a body tag, and create another div or section for contents followed by the header. And give padding to that div.