Is there a way to make navbar logo responsive? - html

So, here is the website I've built using bootstrap 4.
I have a big issue with the logo, as it keeps the same size on all devices.
I've tried adding img-fluid, but if I add this class, the logo shrinks so much on mobile phones, that it looks like a tiny dot. So I've removed this class. Now, on mobile, the hamburger moved on the second line and on the first line of the navbar is the 310 px logo that doesn't even show completly. I want to keep this spacing between the navbar elements as it now, but I think the problem that may be actually comes from my css:
.navbar .navbar-brand {
padding: 5px 200px;
}
.navbar-nav>li {
padding-left: 5px;
padding-right: 5px;
}
.navbar-nav>li {
margin-left: 5px;
margin-right: 5px;
}
This is my html:
<nav class="navbar navbar-light navbar-expand-xl fixed-top ">
<!-- Brand/logo -->
<a class="navbar-brand "> <img src="x" alt="logo" style="width: 310px"></a>
<button class="navbar-toggler" data-target="#collapsingNavbarLg" data- toggle="collapse" type="button">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse" id="collapsingNavbarLg">
<!-- Links -->
<ul class="navbar-nav float-right text-right pr-3">
<li class="nav-item">
<a class="nav-link py-0" href="/" style="font-size: 130%;">Home</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="ChiSono" style="font-size:130%;">Chi Sono</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="Servizi" style="font-size:130%;">Servizi</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="Contattaci" style="font-size:130%;">Contattaci</a>
</li>
<li class="nav-item">
<a class="nav-link py-0" href="AreaClienti" style="font-size:130%;"> Area Clienti</a>
</li>
</ul>
</div>
</nav>
That 200px from padding also keeps the same, and maybe this is why I get all this issue. I am not sure. Also the space between the li elements, as I shrink the page until the point it becomes hamburger. But is there a way to still keep this spacing for my navbar elements, that also resizes? Or is there another way to fix this? Thank you!

I moved everything into a container so that you do not have to use 200px padding to move your logo. This lets the navigation sit similarly to the dimensions/look you had in your code without forcing the position of the elements.
This will let allow you to position your nav items to the right using a css class I added called .navbar-right.
But, because of the new positioning I added another media query to move the hamburger menu. (You may not need this in your coding environment because I was working straight off my desktop with just the CSS, also JS is not added to the example.)
Hope this helps.
.navbar-right {
position: absolute;
right: 0;
}
.relative {
position: relative;
}
#media only screen and (max-width:768px) {
.navbar-brand {
max-width: 100px;
}
/* below is for the demo but might help you position
the hamburger menu on mobile */
.navbar-toggler {
right: 0;
position: absolute;
margin: 10px;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container relative">
<div class="row">
<a class="navbar-brand" href="#">
<img class="img-fluid" src="http://www.studiopirrera.com/Images/ui.png" 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 navbar-right">
<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="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</div>
</div>
</nav>

The best option would be to create diffenrent images files for different view port sizes.
With the srcset attribute, you can select which image should show in which case.
Here an example:
<img src="small.jpg" srcset="small.jpg 320w, medium.jpg 600w, large.jpg 900w" alt="my company">
You give the name/location of the image file, followed by a space and the view port size, when the image should show. It describes until which width (that's why it's w) the image should show. The example above translates to:
the small.jpg is shown until a view port width of 320px
the medium.jpg is shown until a view port width of 600px
the large.jpg is shown until a view port width of 900px
More detailed information can be found here: https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
The positioning can be archieved by the information form brooksrelyt's answer

I solved this problem using an vw units width of image.
This allows the element's aspect ratio to be preserved, based on the viewport width
.navbar-brand img {
max-width: 11vw; /* find suitable value for you */
display: block;
width: 100%;
}

Related

How can I responsively align items on bottom of a sidenav in BS5?

I want to responsively align items on the bottom of a sidenav, made using Bootstrap 5. I incorporated an example of a sidebar from the official Bootstrap Examples, and the .offcanvas class.
In the example, there was a dropdown next to a user profile where the user can access a ton of settings –– aligned at the bottom of the sidebar. However, that just wouldn’t work for me in my version of the offcanvas sidebar. I have tried a multitude of ways, but none of them have worked responsively.
Below is my code, not first and foremost, but at a decent introductory point in this question.
<!DOCTYPE html>
<html lang="en">
<head>
<title>BS5 Offcanvas Sidenav</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.5.0/css/all.min.css" rel="stylesheet">
<style>
.dropup {
position: absolute;
bottom:0;
padding-bottom:2vh;
}
</style>
</head>
<body>
<main>
<nav class="navbar navbar-dark bg-dark d-md-none d-lg-none" aria-label="Dark offcanvas navbar">
<div class="container-fluid">
<a class="navbar-brand" href="#">Side Nav</a>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbarDark" aria-controls="offcanvasNavbarDark">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-start text-bg-dark flex-column d-flex" tabindex="-1" id="offcanvasNavbarDark" aria-labelledby="offcanvasNavbarDarkLabel" style="min-width:160px;max-width:210px">
<div class="offcanvas-header">
<span class="fs-4">Offcanvas</span>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="text-bg-dark offcanvas-body" style="height:100%">
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a href="#" class="nav-link active" aria-current="page">
Home
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
Option A
</a>
</li>
<li class="nav-item dropdown">
<a href="#" class="nav-link align-items-center text-white text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Option B
</a>
<ul class="dropdown-menu dropdown-menu-dark text-small shadow">
<li><a class="dropdown-item" href="#">B. 1</a></li>
<li><a class="dropdown-item" href="#">B. 2</a></li>
<li><a class="dropdown-item" href="#">B. 3</a></li>
<li><a class="dropdown-item" href="#">B. 4</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">B. 5</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">B. 6</a></li>
</ul>
</li>
<li>
<a href="#" class="nav-link text-white">
Option C
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
Option D
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
Option E
</a>
</li>
</ul>
<hr class="mt-auto">
<div class="dropup">
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<img src="https://avatars.githubusercontent.com/u/0" alt="" width="32" height="32" class="rounded-circle me-2">
<strong>Jippy</strong>
</a>
<ul class="dropdown-menu dropdown-menu-dark text-small shadow">
<li><a class="dropdown-item" href="#">New Project...</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Profile</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Sign out</a></li>
</ul>
</div>
</div>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="bg-light mx-auto">
<h1 class="display-5 fw-normal">Navbar with offcanvas</h1>
<p class="fs-5">This is a navbar that uses the <code>.offcanvas</code> Bootstrap class to work. I used a simple sidebar template from the official Bootstrap Examples along with the offcanvas class to make this work. The sidebar only shows on smaller screens.</p>
<p>However, I am facing a <b>problem</b>. The dropup that should be displayed at the bottom of the sidebar? It is made using <code>position: absolute</code>, thus it starts to overlay on top of the other sidebar components if the vertical height is too small. However, I can't figure out how else to put the dropup at the bottom, which is the core of my problem.</p>
<p>Sure, one could think that no one will probably ever go onto a website with a screen height of less than 400px, but with the age of smartwatches, I'm not too sure about that. So, I want to make this responsive. How can I do that?
<p>
<a class="btn btn-primary" href="https://getbootstrap.com" role="button">Made using Bootstrap 5.2.3</a>
</p>
</div>
</div>
</main>
</body>
</html>
As you can see above, I have incorporated some styling to try to get what I want to happen.
<style>
.dropup {
position: absolute;
bottom:0;
padding-bottom:2vh;
}
This works decently well, but does not work correctly on smaller screens.
I have some images to show to explain what’s wrong.
This image shows what the positioning of the dropup is on a standard phone, and I have no complaints here.
However...
When the screen height gets below 400px, the dropup continues to stay at the bottom of the sidenav, causing it to overlay on the other items
EDIT: I don’t have enough reputation to post the images directly, so please follow the links StackOverflow generated.
Citizen
Try using The code Below after changing class names
#media screen and ( max-height: 400px ) {
.logo{
reduce font size of text menu e.g- font-size:12px;
reduce height and width of image e.g- width: 100px; height:30px;
reduce top/bottom padding and margin e-g - margin-top:2px; margin-bottom:2px;
}
.search{
reduce font size of menu items
reduce gap between menu items
}
.main-menu{
reduce font size of menu items
reduce gap between menu items
}
}

How to determine nav-items to get full required width automatically

I'm working with Bootstrap 3 and I'm trying to make a header navbar. Here is my code:
<div class="has-navbar">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler custom-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">
<li class="nav-item active bg-warning first-item m-1">
<a class="nav-link" href="#"><i class="fa fa-home"></i> Home</a>
</li>
<li class="nav-item bg-warning m-1">
<a class="nav-link" href="#"> <i class="fa fa-graduation-cap"></i>Courses</a>
</li>
<li class="nav-item bg-warning m-1">
<a class="nav-link" href="#"><i class="fa fa-shopping-cart"></i> E-learning products</a>
</li>
<li class="nav-item bg-warning m-1">
<a class="nav-link" href="#"><i class="fa fa-newspaper"></i> Articles</a>
</li>
<li class="nav-item bg-warning m-1">
<a class="nav-link" href="#"><i class="fa fa-calendar"></i> Events</a>
</li>
</ul>
</div>
</nav>
</div>
And the result looks like this:
As you can see the menu nav-item E-learning Products does not have enough space to place correctly in the place of nav-item.
However the other nav-items has extra space (as I mentioned out in the image).
So I need to make sure that every nav-item has enough required space based on the length of <a> links of nav-items.
And here comes the CSS code of this navbar:
/* Navbar */
.has-navbar{
margin-top:-10px;
width:100%;
height:30px;
}
.navbar{
background-color: #fff !important;
height:100%;
}
.nav-item{
height:30px;
width:130px !important;
}
.nav-item a{
font-size:13px;
font-weight: bold;
}
.first-item{
margin-right:-50px !important;
}
So here I tried setting width:130px !important; for .nav-item and it didn't work out well. I also tried width:100%; and this is the result:
So how can I properly place each nav-item menu link properly in their required space so the menu links does NOT have extra space AND not enough space?
So what you can do is set its width to max-content, which will be the maximum width that the content contained within can be.
Before(with width: 130px !important;):
After(with width: max-content;):
.nav-item{
height:30px;
//width:130px !important;
width: max-content;
}
Note: If you think it's too short, you could set a min-width value to whatever you like.

What css must I apply to get rid of this useless spacing?

I have a navbar that has some items, 4 of them to the left and one that must always be in the right. The thing is when I introduced the last one to the left, they got one word on top of the other and it looks awful. And one more thing is that when I change the resolution of the monitor, the item that's always on the right moves to the left almost touching the middle.
Some additional info would be that this is part of a project consisting in a web platform for colleges. It is mainly created with SpringBoot and its libraries, fully Java written in backend. Nonetheless, the frontend is mostly HTML, some CSS when I need to make it not look ugly and Javascript in case of animatios of effects. Also not to mention Thymeleaf framework so I can communicate with the backend properly.
I tried many things but I have no idea how to make them look nice. Someone willing to help me on this stylish matter?
I will add two pictures:
this one is when I have my browser put on the 24inch screen
this one is when I have my browser put on the 15.6inch screen of the laptop
And the code below is from the page:
#personal-page {
padding-left: 780px;
font-size: 20px;
}
#admin-page {
padding-left: 730px;
font-size: 20px;
}
#assistant-page {
padding-left: 700px;
font-size: 20px;
}
<html>
<head>
<nav class="fixed-top navbar navbar-dark bg-dark navbar-expand">
<a class="navbar-brand" href="https://curs.upb.ro/">
<span class="fa fa-university"></span> E-Learning Platform
</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="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto" id="navi">
<li class="nav-item active">
<a class="nav-link" href="/">Homepage<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="/menu">Menu Page</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="/admin/students">Students List</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="/admin/camine">Camine Page</a>
</li>
<div th:switch="${isDevAcc}">
<li th:case="'true'" class="nav-item">
<div th:switch="${loggedUsername}">
<a th:case="'iancu'" id="admin-page" class="nav-link fas fa-code" aria-current="page" href="/admin/devAdminPage">
<span> Dev Account :: ADMIN </span>
</a>
<a th:case="'lixi'" id="assistant-page" class="nav-link fas fa-code" aria-current="page" href="/admin/devAdminPage">
<span> Dev Account :: ASISTENT </span>
</a>
</div>
</li>
<li th:case="'false'" class="nav-item" id="personal-page">
<a class="nav-link fas fa-user-secret" aria-current="page" href="#" th:text="${loggedUsername}"></a>
</li>
</div>
</ul>
</div>
</nav>
</head>
<body>
</body>
</html>
Use flexbox to align your navbar horizontally: nav ul { display: flex; }
Then you also can use the :last-child selector to apply margin-left: auto; which will push the last item to the right: nav ul li:last-child { margin-left: auto; }. margin: auto; within a flex-container will consume all remaining space.
nav ul {
display: flex;
}
nav ul li:last-child {
margin-left: auto;
}
/* For styling purpose only */
nav ul {
list-style: none;
padding: 5px;
}
nav li {
margin: 0 10px;
}
<nav>
<ul>
<li>E-Learning Plattform</li>
<li>Homepage</li>
<li>Menu Page</li>
<li>Students List</li>
<li>Camine Page</li>
<li>Admin</li>
</ul>
</nav>

Padding with adjustments on a Bootstrap 4 navbar menu system

New to Bootstrap 4 and making a dummy/mockup page with a header to get use to the navbar system.
I created this jsFiddle (full code) here, but the gist of my page is:
index.html
<nav class="navbar navbar-expand-lg">
<a class="navbar-brand" href="javascript:void(0)">
<img src="https://raw.githubusercontent.com/bitbythecron/bootstrap-troubleshooting/main/dummy-logo.png" class="img-fluid mainlogo" alt="Responsive image">
</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navb">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navb">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="aboutMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
About
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="fizzMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Fizz
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="buzzMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Buzz
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="foobarMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Foobar
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="resourcesMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Resources
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="helpMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Help
</a>
</li>
<li class="nav-item">
<a class="nav-link red-button" href="javascript:void(0)">WATCH DEMO</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Sign In</a>
</li>
<li class="nav-item">
<a class="nav-link bordered" href="javascript:void(0)">Sign Up</a>
</li>
</ul>
</div>
</nav>
main.css
html, body {
height: 100%;
font-family: 'Lato';
}
.bordered {
border-radius: 5px;
border: 1px solid white;
}
.navbar {
background-color: #00142e;
}
.red-button {
border-radius: 5px;
border: 1px solid #A81E30;
background-color: #A81E30;
color: beige;
}
.mainlogo {
width: 35%;
}
When this runs I get:
The main problem here is the thickness of the padding around the navbar. How do I make it so that there is no padding, and that the height of the navbar is either the same as that of the logo and menu links, or at most just a pixel or two greater than? I did try adding padding: 0px; to the navbar style but that did not affect anything.
Also I would like to center all the navbar content (logo + menu items)...any ideas there? I did try adding d-flex justify-content-center to navbar-collapse but that also did nothing. Thanks in advance!
Update
I updated my jsFiddle with the suggested changes from below and now I'm seeing:
So I'm still not seeing the navbar (again: logo + links) content centered and I'm seeing undesired padding, meaning the blue bar is a little too tall for what I'm looking for (I want something shorter and hugging the logo + links a little tighter).
To fix the centering, add align-item: center to your unordered list. That should be the child element of your navbar-collapse element, and it will center all your links vertically.
As for the padding, I think that it would be better to remove class="img-fluid mainlogo" alt="Responsive image" and instead just give your image a height property that you like. When I did just that, it also looked like it fixed your centering problem as well.
Let me know if that worked for you!
edited to add code snippet
/*old selector for mainlogo*/
.mainlogo {
width: 35%;
}
/*new selector for mainlogo*/
.mainlogo {
height: 50px;
}
/*added selector. targets ul elements that are descendents of element with id "navb"*/
#navb ul {
align-items: center;
}
Navbar after changes
I forked your work in JSFiddle, see what I did.
In fact, I wrapped your <nav> whithin an <header>, then I have added the bootstrap class container to get the content centered depending on the screen size with media-queries.
Also, I have changed your content class container-fluid to container in order to have the same sizing results between the navbar and the rest of your page.
I removed the img-fluid on your image, in order to avoid stretching the image if the page is resized.
Also, as your question in an other post where I answered, I have changed the navbar background to fit your brand-logo background color ;)
And in bonus I added the class navbar-dark, now you can see your burger menu when nav items are collapse. Because since bootstrap 4 :
.navbar-default is now .navbar-light, though .navbar-dark remains the same. One of these is required on each navbar. However, these classes no longer set background-colors; instead they essentially only affect color.
Bonus 2 : I removed your red-button class, and changed it to btn btn-danger which is quite the same, but with hover rules. And for your sign-up button, I added btn btn-success. I did that to let you learn on those classes too, because it is not necessary to reinvent the wheel :)
Then, you can use in your questions / answers in StackOverflow, the built-in JSFiddle Javascript/HTML/CSS snippet CTRL-M as below :
html, body {
height: 100%;
font-family: 'Lato';
}
.bordered {
border-radius: 5px;
border: 1px solid white;
}
header#nav-container{
background-color: #001a31;
}
#navb ul {
align-items: center;
}
.mainlogo {
height: 50px;
}
<!DOCTYPE html>
<html>
<head>
<title>Special Nonprofit</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<link rel='shortcut icon' type='image/x-icon' href='favicon.ico' />
<link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght#0,300;1,300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<header id="nav-container">
<nav class="navbar navbar-dark navbar-expand-lg container">
<a class="navbar-brand" href="javascript:void(0)">
<img src="https://raw.githubusercontent.com/bitbythecron/bootstrap-troubleshooting/main/dummy-logo.png" class="mainlogo" alt="Responsive image">
</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navb">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navb">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="aboutMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
About
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="fizzMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Fizz
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="buzzMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Buzz
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="foobarMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Foobar
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="resourcesMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Resources
</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="javascript:void(0)" id="helpMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Help
</a>
</li>
<li class="nav-item">
<a class="nav-link btn btn-danger" href="javascript:void(0)">WATCH DEMO</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Sign In</a>
</li>
<li class="nav-item">
<a class="nav-link btn btn-success" href="javascript:void(0)">Sign Up</a>
</li>
</ul>
</div>
</nav>
</header>
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.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.5.2/js/bootstrap.min.js"></script>
</body>
</html>
Try This!
.sidebar {
height: 100%;
width: 0;
position: fixed;
/*Stays in place */
background-color: #303630;
/*Grey*/
overflow-x: hidden;
color:white;
z-index: 12;
/*for Disabling horizontal scroll */
}
/* Position and style for the sidebar links */
.sidebar a {
padding: 10px 10px 10px;
font-size: 25px;
color: #ffffff;
display: block;
transition: 0.3s;
}
/* the links change color when mouse hovers upon them*/
.sidebar a:hover {
color: #ffffff;
}
/* Position and style the for cross button */
.sidebar .closebtn {
position: absolute;
top: 0;
right: 25px;
}
/* Style for the sidebar button */
.openbtn {
font-size: 25px;
background-color: #000000;
color: #ffffff;
padding: 10px 10px 10px;
border: none;
position: fixed;
z-index: 12;
}
/* the sidebar button changes
color when mouse hovers upon it */
.openbtn:hover {
color: #FFFFFF;
}
/* pushes the page content to the right
when you open the side navigation */
#main {
transition: margin-left .5s;
/* If you want a transition effect */
padding: 10px;
}
<div id="sidebar" class="sidebar">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">
×
</a>
Placeholder 1
Placeholder 2
Placeholder 3
Placeholder 4
Placeholder 5
Placeholder 6
</div>
<div id="main">
<button class="openbtn" onclick="openNav()">
Hello
</button>
</div>
<script>
/* Sets the width of the sidebar
to 250 and the left margin of the
page content to 250 */
function openNav() {
document.getElementById(
"sidebar").style.width = "250px";
document.getElementById(
"main").style.marginLeft = "250px";
}
/* Set the width of the sidebar
to 0 and the left margin of the
page content to 0 */
function closeNav() {
document.getElementById(
"sidebar").style.width = "0";
document.getElementById(
"main").style.marginLeft = "0";
}
</script>
I have moved all the navbar content to the center with mx-auto class. removed the padding for top and bottom with py-0 class. this equal to padding-top: 0; padding-bottom: 0; then with media queries. I'm switching between main and secondary logo.
Here's the code:
https://codepen.io/lachiweb/pen/dyXBGvd

Adding a subtitle to a Bootstrap Navbar

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