I am building a site for a client using bootstrap and for some reason the images I use in my nav-icons don't always appear.
When I first load the page, I notice that the images don't appear and have a width of 0. If you re-load the page the images show up.
Is there something going on here or something I can do to make sure they are always there and don't have that hiccup?
Here is my code for the nav-bar:
<nav class="navbar navbar-collapse text-center navbar-expand-lg mt-4 navbar-light">
<button class="navbar-toggler nav-btn" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon float-right"></span>
</button>
<div class="collapse navbar-collapse px-0" id="navbarSupportedContent">
<ul class="navbar-nav algin-items-center d-flex ml-5 pl-5">
<li class="nav-item col-2 text-center expand-lg">Home</li>
<img src="images/shapeimage_1.png" width="26" height="26" class="nav-ico after my-auto" />
<li class="nav-item col-2 text-center" id="about">About Us</li>
<img src="images/dogpaw_1.png" width="26" height="26" class="nav-ico after my-auto" />
<li class="nav-item col-2 text-center" id="services">Services</li>
<img src="images/icon-bowl_46.png" width="26" height="26" class="nav-ico after my-auto" />
<li class="nav-item col-2 text-center id="adopt"">Adopt</li>
<img src="images/heart2_3.png" width="26" height="26" class="nav-ico after my-auto" />
<li class="nav-item col-2 text-center" id="donate">Donate</li>
<img src="images/icon-house_46_1.png" width="26" height="26" class="nav-ico after my-auto" />
<li class="nav-item col-2 text-center" id="events">Events</li>
</ul>
</div>
</nav>
The images between the li are what sometimes change width.
I typically open in chrome and the developer tools show that the image is there and unbroken, but has a width of 0.
Reload the page and they are there without any problems and generally remain there for each re-load unless I Ctrl + F5 and force a full load from the server.
Ok, after looking at the comments and doing some trial and error, it seems simply adding <li> to the img tag is enough to make them consistently stay put. They still collapse at my breakpoint and work as I want them to without any obvious side effects. Thank you #Bogdan Lapchenkov for the idea and the suggestion. I'd up your answer if it were an answer mate.
Related
The top down padding is set to 3% but left right padding of 15% doesn't work. Can someone explain what is wrong here? I want to set the top-down padding of 3% and left-right padding of 15% with respective to fluid container. But it seems that left-right padding is not working. I debugged it using chrome developer tools. But the left- right padding were crossed out.
<div class="container-fluid">
<div class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand" href="">Tindog</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<ul class="navbar-nav ms-auto">
<li class ="nav-item">
<a class="nav-link" href="">Contact</a>
</li>
<li class ="nav-item">
<a class="nav-link" href="">Pricing</a>
</li>
<li class ="nav-item">
<a class="nav-link" href="">Download</a>
</li>
</ul>
</div>
</div>
<!-- Title -->
<div class="row">
<div class="col-lg-6 col-md-6">
<h1>Meet new and interesting dogs nearby.</h1>
<button type="button">Download</button>
<button type="button">Download</button>
</div>
<div class="col-lg-6 col-md-6">
<img src="images/iphone6.png" alt="iphone-mockup">
</div>
</div>
</div>
CSS FILE
.container-fluid{
padding: 3% 15%;}
Put " <link rel="stylesheet" " at the bottom of head so i'ts bellow the bootstrap link :) Top to bottom priority!
Bootstrap containers have horizontal padding already set. You can limit the width like this <div class="container-fluid" style="max-width: calc( 100% - (15% * 2) )">...</div>
From my experience, bootstrap has default dimensions for its margin and padding. Setting custom dimensions may not work.
container-fluid is a custom bootstrap class. You cannot override it. You'd need to add another class if you want to customize the padding.
or customise according to the docs: https://getbootstrap.com/docs/5.2/layout/containers/#how-they-work
We are having trouble with our responsive navigation covering content.
When the user toggles the navigation button, we want it to push the H1 and down the screen. I am thinking that our css for the body is effecting this. I cannot think of a decent solution for this, but I have considered having the navigation have a background, but it will still cover our "Denver Moving and Storage" content.
We're still learning how to use stackoverflow and we're thankful for any help you guys may be able to offer.
html,body
{
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
This is our code:
<!-- container with bg img -->
<div class="cover">
<div class="container">
<!-- NAV Here -->
<nav class="navbar navbar-expand-sm navbar-dark d-flex" aria-label="responsive navbar">
<a class="navbar-brand" href="index.html"><img src="img/the-other-side-moving-storage-color-white.png" width="75%" height="75%"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#responsive-navbar" aria-controls="responsive-navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="responsive-navbar">
<ul class="navbar-nav me-auto mb-2 mb-sm-0">
<li class="nav-item">
<a class="nav-link" href="denver-moving-services.html">Moving</a>
</li>
<li class="nav-item">
<a class="nav-link" href="denver-storage-company.html">Storage</a>
</li>
<li class="nav-item">
<a class="nav-link" href="receiving-and-delivery.html">Furniture Delivery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about-us.html">About</a>
</li>
<li class="nav-item">
<button class="btn btn-tosa" type="submit">Free Estimate</button>
</li>
</ul>
</div>
</nav>
<!-- Nav end -->
</div>
<!-- FS Hero -->
<div class="container-xl mb-4">
<div class="row text-center">
<div class="col-12">
<h1 class="py-5">Denver Moving and Storage</h1>
<button type="button" class="btn btn-tosa mx-3">Free Estimate</button>
<button type="button" class="btn btn-outline-tosa mx-3">Our Story</button>
</div>
</div>
</div>
<!-- End FS Hero -->
</div>
<!-- End Cover -->
I don't know if your body CSS is affecting it or not, since you didn't post that out. But just by looking at your HTML, I see something wrong with your button toggler:
<button ... data-bs-toggle="collapse" data-bs-target="#responsive-navbar" />
Where did you get this kind of syntax from? In Bootstrap documentation, there is no -bs on the data attribute.
In order for the toggler to work properly, you need to remove -bs.
Minor improvement
Your "free estimate" button. Bootstrap has a button style to make an anchor tag look like a button. You don't need to wrap a button with an anchor tag. You can change it to something like:
<li class="nav-item">
<a class="btn btn-success" href="free-estimate.html">Free Estimate</a>
</li>
demo: https://jsfiddle.net/davidliang2008/p4ofdcae/8/
I am trying to create my header using bootstrap so that when it is in anything larger than small screen all that shows up is the brand and the links do not display, but when the screen is in small there is the collapsible button.
My site is #:
https://jspurling22.github.io/coursera-test/module3-sol/index.html
<div id="collapsable-nav" class="collapse navbar-collapse d-block d-sm-none">
<ul id="nav-list" class="nav navbar-nav navbar-right ">
<li class="link-button">
Chicken
</li>
<li class="link-button">
Beef
</li>
<li class="link-button">
Sushi
</li>
</ul>
</div>
I added the d-block d-sm-none and tried it in the div and the ul spots but nothing is working for me.
Any help would be great.
Thanks!
If I understood your question probably you should use the class navbar-expand-[sm-md-lg] which is all you need to hide the links.
<div id="collapsable-nav" class="collapse navbar-collapse navbar-expand-sm"> </div>
I also recommend upgrading to bootstrap 4 since bootstrap 5 is already up.
Do please let me know if that didn't help.
First off the problem was that I was using Bootstrap 3 and calling Bootstrap 4. Changed to bootstrap 4, added .navbar-expand-xs like:
<nav class="navbar navbar-expand-xs navbar-dark bg-dark">
and added .d-block and .d-sm-none to the button
<button class="navbar-toggler d-block d-sm-none" type="button" data-
toggle="collapse" data-target="#navbarSupportedContent" aria-
controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle
navigation">
I have a bootstrap 4 navbar which is set to expand on lg and collapse on small devices. This works on a default navbar height but whenever I set the navbar to a height smaller than the default height the expand for the small devices doesnt work...
HTML-Code:
<header style="background-color: blue;color: white;font-size: 14px">
<div class="container">
<nav class="navbar navbar-expand-lg navbar-default" style="height:30px">
<ul class="navbar-nav mr-auto flex-row justify-content-start">
<li class="nav-item">
<a href="#" class="mr-4">
<i class="fa fa-twitter-square fa-lg"></i>
</a>
</li>
</ul>
<a class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<i class="fa fa-road"></i>
</a>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav ml-auto d-flex">
<li class="nav-item active d-inline">
<a class="nav-link" href="#">Home1 <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active d-inline">
<a class="nav-link" href="#">Home2 <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
</div>
</header>
The content is also not set in the middle. What am I missing out?
The above shows the following. Even the expand fails
I want to define the height as 30px and i want the content to center vertically in the set height.
Actually Bootstrap navbar height is not defined by a CSS height property, but it changes with <a> padding and their content.
Try to add py-0 CSS class to <a> of your navbar to remove padding top and bottom.
See this example: https://codepen.io/navalex/pen/jOPXxor
Setting the height to 30px here is causing your issue:
<nav class="navbar navbar-expand-lg navbar-default" style="height:30px">
Here is a codepen that shows your code in a standard boostrap4 template with that inline style commented out:
codepen
I have a Bootstrap 4 website with a navbar. The navbar has a brand part with an image and title text, and then there's the rest of the navbar. You can see it here: https://jsfiddle.net/zmbq/aq9Laaew/218793/
Now, I want to add a subtitle, under the title "A Digital Onomasticon". The problem is - the substitle is long, and I want it to extend below the nav links.
I tried everything I could think of and couldn't figure out how to do that.
NOTE: the answer to this question is not sufficient, as it yields something like this: https://jsfiddle.net/zmbq/7et2uz0w/
Wrap the brand and links in a separate flexbox (d-flex) div...
<nav class="navbar navbar-light bg-light navbar-expand-sm flex-nowrap align-items-start">
<a class="navbar-brand" href="#">
<img src="http://onomasticon.researchsoftwarehosting.org/assets/images/seal-impression.png">
</a>
<div class="d-flex flex-column">
<div class="d-sm-flex d-block flex-nowrap">
<a class="navbar-brand" href="#">A Digital Onomasticon</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarOnavbarNavptions" 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">
<li class="nav-item">
<a class="nav-link" href="#">Item one</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item two</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item three</a>
</li>
</ul>
</div>
</div>
<small>A lot more text that goes under the links and should be cleverly placed, and isn't</small>
</div>
</nav>
https://www.codeply.com/go/9SK8ItOyzw
Related: Bootstrap 4 navbar with 2 rows
You can set the subtitle to position absolute to remove it from the normal content flow. It's unclear how it should look on mobile, I simply hide it in the media query. Example:
<a class="navbar-brand" href="#">
<img src="http://onomasticon.researchsoftwarehosting.org/assets/images/seal-impression.png">
A Digital Onomasticon
<small>A lot more text that goes under the links and should be cleverly placed, and isn't</small>
</a>
.navbar-brand small {
display: block;
font-size: 10px;
white-space: normal;
position: absolute;
}
#media (max-width: 575.98px) {
.navbar-brand small {
display: none;
}
}
JsFiddle