I'm build a SPA app with Angular-CLI and Node.Js, using WebStorm, and I can't figure out why my navbar won't collapse.
When the page is small enough, the nav-items simply disappear.
I'm not using the navbar-expand class (instead using the navbar-expand-sm which isn't supposed to prevent collapsing), and other than that, I found nothing that's supposed to cause this problem.
My navbar.component.html:
<nav class="navbar navbar-expand-sm navbar-brown fixed-top">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" (click)="clickedHome()">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" (click)="clickedForums()">Forums</a>
</li>
<li class="nav-item">
<a class="nav-link" (click)="clickedMyZone()">MyZone</a>
</li>
</ul>
</div>
</nav>
<div class="jumbotron text-center" id="primary_jumbotron_display">
<div id="primaryDisplayBorder">
<div id="primaryDisplayContent">{{primaryDisplayBorderTitle}}</div>
<p>{{primaryDisplayBorderContent}}</p>
</div>
</div>
My navbar.component.css:
#import url(//db.onlinewebfonts.com/c/460e8698563db983434874f8f371a7d1?family=Museo);
.jumbotron {
height: 40vh;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#primary_jumbotron_display {
background-image: url('client/assets/images/FriendLancer_banner.jpg');
font-family: Museo;
font-size: x-large;
background-size: cover;
align-content: center;
color: saddlebrown;
margin-bottom: 0;
}
#primaryDisplayContent {
font-size: 7ex;
}
.navbar-brown {
background-color: saddlebrown !important;
box-shadow: #222222;
}
.navbar {
-webkit-box-shadow: 0 8px 6px -6px black;
-moz-box-shadow: 0 8px 6px -6px black;
box-shadow: 0 8px 6px -6px black;
}
.navbar-nav {
font-family: Museo;
font-size: medium;
}
.navbar-nav > li {
padding-left: 15px;
padding-right: 15px;
}
.nav-item {
transition: all 0.3s ease;
}
.navbar-nav a {
color: silver;
}
.navbar-nav a:hover {
color: saddlebrown;
letter-spacing: 1.3px;
background-image: linear-gradient(to right, sandybrown, rosybrown);
}
Any help would be appreciated.
Related
My bootstrap Navbar is white and despite trying everything i can find on Stack i cant override the white to make it transparent.
I have tried setting the background to transparent
The image behind is set to VH100 so should be behind the nav
I have tried using Inspect and targeting every colour instruction i could find
I removed the bg class from the navbar thinking that would help
Here is my html
<nav class="navbar navbar-expand-sm navbar-light">
<div class="container-fluid">
<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">
<img src="/assets/images/MothersSpinesLogo.png" alt="Mothers Spines MS Logo">
<ul id="nav" class="navbar-nav ms-auto">
<li class="active nav-item">
<a class="nav-link"href="index.html">HOME</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>
</nav>
and my CSS;
/* Navigation */
.navbar-brand {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
max-height: 60px;
max-width: 60px;
margin-left: 30px;
}
.navbar {
align-items: end;
background: none;
background-color: rgba(0, 0, 0, 0.0);
--bs-navbar-nav-link-padding-x: 3.5rem;
font-family: 'Montserrat';
font-size: 120%;
list-style-type: none;
letter-spacing: 1px;
--bs-navbar-toggler-border-color: rgba(0, 0, 0, 0.0);
}
.navbar a {
text-decoration: none;
color: #252525;
}
.nav-item {
padding-top: 25px;
}
Screenshot of Nav and Inspect open
.navbar { background-color: transparent; }
Add the following to the image: height: 100vh;, position: absolute; and top: 0;.
If you just set height: 100vh; to the image, the image will be full viewport height, but it will start AFTER the navbar. You want to place it below the navbar. You do this by setting position: absolute; and top: 0;.
In short, the problem is caused by the image.
It looks like there are issues with element placement. Code provided does work for overlaying the image.
img#bg {
position: absolute;
}
/* Navigation */
.navbar-brand {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
max-height: 60px;
max-width: 60px;
margin-left: 30px;
}
.navbar {
align-items: end;
background: none;
background-color: transparent;
--bs-navbar-nav-link-padding-x: 3.5rem;
font-family: 'Montserrat';
font-size: 120%;
list-style-type: none;
letter-spacing: 1px;
--bs-navbar-toggler-border-color: rgba(0, 0, 0, 0.0);
}
.navbar a {
text-decoration: none;
color: #252525;
}
.nav-item {
padding-top: 25px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<img id="bg" src="https://st3.depositphotos.com/1021722/13762/i/600/depositphotos_137623752-stock-photo-art-spring-background-fresh-flower.jpg">
<nav class="navbar navbar-expand-sm navbar-light">
<div class="container-fluid">
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<a href="index.html" class="navbar-brand">
<img alt="Mothers Spines MS Logo">
</a>
<ul id="nav" class="navbar-nav ms-auto">
<li class="active nav-item">
<a class="nav-link" href="index.html">HOME</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>
</nav>
I am responsible for upgrading Bootstrap from 3 to 5, and allow some minor UI changes, like px-wise changes. However I am suffering from navbar transition like the below discussed.
Here is the simplified version of my navbar using Bootstrap 3.
.image-header-logo {
margin: -5px;
height: 34px;
}
.custom-navbar {
box-shadow: 0px 0px 6px rgb(255 100 0);
}
.navbar {
border: 0px;
}
.navbar-nav > li.active {
box-shadow: inset 0px -5px 0px 0px rgba(255, 119, 0, 0.68);
}
.navbar-nav > li > a {
color: #ff6633;
}
.navbar-nav > li > a:hover {
background: rgb(255, 119, 0);
color: #ffffff;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar custom-navbar">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img class="image-header-logo" src="https://www.gravatar.com/avatar/e8bf61002bf07be4ca6085c301f990c0?s=64" />
</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right" >
<li><a class="nav-menu-item">Welcome</a></li>
<li class="active">
<a class="nav-selected-menu-item nav-text-color" href="#">Java</a>
</li>
<li>
<a class="nav-selected-menu-item nav-text-color" href="#">PHP</a>
</li>
</ul>
</div>
</div>
</nav>
And here is the new code using Bootstrap 5.
body {
font-size: 14px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
.image-header-logo {
height: 2.5rem;
}
.navbar {
padding: 0 1rem;
margin-bottom: 6px;
}
.custom-navbar {
box-shadow: 0px 0px 6px rgb(255 100 0);
}
.nav-item {
cursor: pointer;
padding: 0.5rem 0;
}
.navbar .navbar-collapse .navbar-nav .nav-item.active {
box-shadow: inset 0px -5px 0px 0px rgba(255, 119, 0, 0.68);
cursor: pointer;
}
.navbar .navbar-collapse > .navbar-text,
.navbar .navbar-collapse .navbar-nav .nav-item > .nav-link {
color: #ff6633;
}
.navbar .navbar-collapse .navbar-nav .nav-item:hover {
background: rgb(255, 119, 0);
color: #ffffff; /* FIXME: not work == */
}
/* FIXME: need to add this, but in the outskirt it does not work */
.navbar .navbar-collapse .navbar-nav .nav-item > .nav-link:hover {
color: #ffffff;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-md navbar-light custom-navbar">
<a class="navbar-brand" href="/i/trade">
<img class="image-header-logo" src="https://www.gravatar.com/avatar/e8bf61002bf07be4ca6085c301f990c0?s=64" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#myNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="myNavbar">
<span class="navbar-text ms-auto">Welcome</span>
<ul class="navbar-nav">
<li class="nav-item active px-1">
<a class="nav-link">Java</a>
</li>
<li class="nav-item px-1">
<a class="nav-link">PHP</a>
</li>
</ul>
</div>
</nav>
As it seems there is a rendering issue in stackoverflow, I have also place the code in jsfiddle.
The same codebase can also be found in jsfiddle.
Bootstrap 3: https://jsfiddle.net/hphchan/hfo9njc3/66/
Bootstrap 5: https://jsfiddle.net/hphchan/4yrxu8dk/60/
Most of the UI generated from the 2 version looks similar, but with the below issue.
When hover on nav-item but not nav-link in Bootstrap 5, as there is a padding in nav-item, making the hover color changes not work.
which can be seen in the picture below.
And here is the Bootstrap 3 version, which works in the edge.
I understand why it does not work due to the class structure change. However what I do not know is how to make the hover behavior the same.
You can emulate the behavior using the hover selector only for the nav-link class and forgetting the nav-item to simplify what style applies when hovered.
This way nav-link should have color: #ff6633 when not hovered and color: #ffffff when hovered:
.navbar .navbar-collapse>.navbar-text,
.navbar .navbar-collapse .navbar-nav .nav-item>.nav-link {
color: #ff6633;
}
.navbar .navbar-collapse .navbar-nav .nav-item>.nav-link:hover {
color: #ffffff;
background: rgb(255, 119, 0);
}
Also, remove the ** margin-bottom ** property for the .navbar.
The markup for the ul would be:
<ul class="navbar-nav">
<li class="nav-item active mx-2">
<a class="nav-link py-3 px-3">Java</a>
</li>
<li class="nav-item ms-2">
<a class="nav-link py-3 px-3">PHP</a>
</li>
</ul>
Working example:
body {
font-size: 14px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.image-header-logo {
height: 2.5rem;
}
.navbar {
padding: 0 1rem;
/* override default 0.5rem 1rem */
/* box-shadow: 0px 0px 6px rgb(255, 100, 0); */
/* TODO: placed in #header instead */
margin-bottom: 6px;
/* reserve space for the box-shadow */
}
.custom-navbar {
box-shadow: 0px 0px 6px rgb(255 100 0);
}
/* to create sadow on the bottom */
.nav-item {
cursor: pointer;
}
.navbar .navbar-collapse .navbar-nav .nav-item.active>.nav-link {
box-shadow: inset 0px -5px 0px 0px rgba(255, 119, 0, 0.68);
cursor: pointer;
}
/* to show orange in color on the line */
/* need to specify for so long, so that it can win without use of !important... == */
.navbar .navbar-collapse>.navbar-text,
.navbar .navbar-collapse .navbar-nav .nav-item>.nav-link {
color: #ff6633;
}
/* FIXME: need to add this, but in the outskirt it does not work */
.navbar .navbar-collapse .navbar-nav .nav-item>.nav-link:hover {
color: #ffffff;
background: rgb(255, 119, 0);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css">
<nav class="navbar navbar-expand navbar-light custom-navbar py-0">
<a class="navbar-brand" href="/i/trade">
<img class="image-header-logo" src="https://www.gravatar.com/avatar/e8bf61002bf07be4ca6085c301f990c0?s=64" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#myNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="myNavbar">
<span class="navbar-text ms-auto">Welcome</span>
<ul class="navbar-nav">
<li class="nav-item active mx-2">
<a class="nav-link py-3 px-3">Java</a>
</li>
<li class="nav-item ms-2">
<a class="nav-link py-3 px-3">PHP</a>
</li>
</ul>
</div>
</nav>
I'm making this Bootstrap 5 navbar, which should collapse at md breakpoint. After the collapse, it should show navlinks in two columns.
When I hit the breakpoint, my navbar is expanded and toggle button doesn't work.
It changes, when I switch off the display: flex property for the navbar - the collapse function works, but my ul's (in which I group li's) are in one column.
How can I reach my goal here - navbar with six elements collapses at md breakpoint and breaks the links into two columns?
<nav class="navbar navbar-expand-md navbar-light sticky-top w-100">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNavbar"
aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNavbar">
<ul class="navUl navbar-nav">
<li class="nav-item">
<a class="nav-link text-nowrap" aria-current="page" href="/aboutMe">o mnie</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
data-bs-toggle="dropdown" aria-expanded="false">portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link text-nowrap" href="/beforePS">przed sesją</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link navbar-brand" href="/">
<img src="/images/logoKP-trans.png" class="img-fluid" alt="Karolina_photography_logo" id="logo">
</a>
</li>
</ul>
<ul class="navUl navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/voucher">vouchery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/pricing">pakiety</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact">kontakt</a>
</li>
</ul>
</div>
css (very messy, to be optimised):
body {
background-color: #f8edeb;
margin: 0;
font-family: "Quicksand", sans-serif;
font-weight: 400;
opacity: 0;
animation: fadeIn 0.5s;
transition: opacity 0.5s;
}
main {
align-items: center;
margin: 3% 20%;
max-width: 80%;
}
.navbar,
.footer {
background-color: #fae1dd;
color: rgba(0, 0, 0, 0.5);
box-shadow: 10px 5px 5px rgba(202, 178, 174, 0.5);
padding-top: 0;
text-align: center;
}
#mainNavbar {
display: flex;
justify-content: center;
align-items:flex-end;
}
.navbar-brand {
margin: 0;
}
.nav-item {
display: flex;
margin: 0 0.8em;
font-size: 1.2rem;
}
.navUl {
padding-bottom: 10px;
}
.navbar-brand {
max-width: 300px;
height: auto;
padding-bottom: 0;
top: 0.4rem;
}
#mainNavbar a:hover,
#socialIcons a:hover,
.loginButton a:hover {
color: white;
text-shadow: 5px 5px 10px white;
-moz-transition: all 0.2s ease-in;
-o-transition: all 0.2s ease-in;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.dropdown-menu {
border-radius: 0.5rem;
background-color: rgba(250, 225, 221, 0.9);
}
.dropdown-item:hover {
background-color: transparent;
}
#socialIcons {
color: rgba(0, 0, 0, 0.5);
position: absolute;
top: 10px;
right: 10px;
}
#socialIcons a,
#kidsPshoot {
text-decoration: none;
color: rgba(0, 0, 0, 0.5);
display: inline;
margin-right: 0.5rem;
}
.fade_rule {
height: 1px;
background-color: #e6e6e6;
width: 50%;
margin: 0 auto;
background-image: linear-gradient(left, white 2%, #e6e6e6 50%, white 98%);
background-image: -o-linear-gradient(left, white 2%, #e6e6e6 50%, white 98%);
background-image: -moz-linear-gradient(
left,
white 2%,
#e6e6e6 50%,
white 98%
);
background-image: -webkit-linear-gradient(
left,
white 2%,
#e6e6e6 50%,
white 98%
);
background-image: -ms-linear-gradient(left, white 2%, #e6e6e6 50%, white 98%);
background-image: -webkit-gradient(
linear,
left bottom,
right bottom,
color-stop(0.02, white),
color-stop(0.5, rgb(250, 182, 170)),
color-stop(0.98, white)
);
}
#media (max-width:1200px) {
.nav-item, .dropdown-item, #aboutMeText, p, li, h5 {
font-size: 1rem;
}
#logo {
max-width: 230px;
}
.navUl {
padding-bottom: 5px;
}
}
#media (max-width:992px) {
#logo {
max-width: 200px;
/* position: absolute;
left: 70%;
top: 30%; */
}
.nav-item, .dropdown-item {
font-size: 0.9rem;
}
.nav-item {
margin: 0;
}
}
#media (max-width:768px) {
.nav-item, .dropdown-item, #navbarDropdownMenuLink, p, li {
font-size: 0.7rem;
margin-left: 0;
text-align: left;
min-width: 100px;
}
#mainNav {
position:unset;
}
}
It’s not clear what all of your CSS is for. Some, like setting the opacity on the body to 0 hide everything. It’s best to have a running snippet with your question.
If you want your logo in the center, you can split your menus into two unordered lists.
For applying margin such as to the bottom of the navbar-nav, use the Bootstrap spacing utility classes (mb-1 mb-md-2).
Copy the Bootstrap media query logic (min-width, not max-width – it’s difficult to troubleshoot with two methods) and apply your media queries starting with the smallest size (no media query), followed by increasing media query sizes (min-width: 576px, min-width: 768px, etc.).
Rather than using smaller text for smaller screens, keep the text the same size and adjust the position if the text won’t fit (smaller text is more difficult for some users to read).
One way to have two columns for the links in the collapsed version is to add a spacer div (.break) that can force the navbar-collapse divs to the next row, and then set their width to 50%.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.bundle.min.js"></script>
<style>
body {
background-color: #f8edeb;
font-family: "Quicksand", sans-serif;
}
.navbar,
.footer {
background-color: #fae1dd;
color: rgba(0, 0, 0, 0.5);
box-shadow: 10px 5px 5px rgba(202, 178, 174, 0.5);
padding-top: 0;
}
.navbar-brand {
margin: 0;
max-width: 300px;
height: auto;
padding-bottom: 0;
top: 0.4rem;
}
#mainNavbar a:hover,
#socialIcons a:hover,
.loginButton a:hover {
color: white;
text-shadow: 5px 5px 10px white;
-moz-transition: all 0.2s ease-in;
-o-transition: all 0.2s ease-in;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.dropdown-menu {
border-radius: 0.5rem;
background-color: rgba(250, 225, 221, 0.9);
max-width: 75%;
}
.dropdown-item:hover {
background-color: #E0C9C5;
}
#logo {
max-width: 120px;
height: auto;
}
#media (min-width: 576px) {
#logo {
max-width: 160px;
}
}
#media (min-width: 768px) {
#logo {
max-width: 200px;
}
.navbar-collapse.flex-basis-md-0 {
flex-basis: 0;
}
}
#media (min-width: 992px) {
#logo {
max-width: 230px;
}
}
#media (min-width: 1200px) {
#logo {
max-width: 300px;
}
}
.navbar-collapse {
max-width: 50%;
}
/* Inserting div.break between two flex items will make
* the flex item that comes after it break to a new row -
* this is how the two-column navbar-collapse are moved to
* a separate row. */
.break {
flex-basis: 100%;
height: 0;
}
#media (min-width: 768px) {
.break {
display: none;
}
}
</style>
<nav class="navbar navbar-expand-md navbar-light sticky-top w-100">
<div class="container-fluid justify-content-md-around">
<a class="navbar-brand order-md-1" href="#">
<img id="logo" src="https://via.placeholder.com/120x40.png/E5FFFF/?text=KP-Trans" alt="" width="300" height="60">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".mainNavbar" aria-controls="mainNavbar1 mainNavbar2" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="break"></div>
<div class="collapse navbar-collapse flex-basis-md-0 mainNavbar" id="mainNavbar1">
<ul class="navbar-nav mx-md-auto">
<li class="nav-item">
<a class="nav-link text-nowrap" aria-current="page" href="/aboutMe">o mnie</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
portfolio
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">portfolio #1</a></li>
<li><a class="dropdown-item" href="#">portfolio #2</a></li>
<li><a class="dropdown-item" href="#">portfolio #3</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link text-nowrap" href="/beforePS">przed sesją</a>
</li>
</ul>
</div>
<div class="collapse navbar-collapse flex-basis-md-0 align-self-start align-self-md-center mainNavbar order-md-2" id="mainNavbar2">
<ul class="navbar-nav mx-md-auto">
<li class="nav-item">
<a class="nav-link" href="/voucher">vouchery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/pricing">pakiety</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact">kontakt</a>
</li>
</ul>
</div>
</div>
</nav>
<section>
<div class="container">
<div class="row">
<div class="col vh-100">
<p class="text-center">
Center
</p>
</div>
</div>
</div>
</section>
It's also helpful if you include a placeholder image at the right size to match your logo. I guessed at 120 by 40
I'm trying to make my menu look like the one on this page.
But somehow it's not working. This is my website so far. My main pet peeves with this is the menu items are not centered and the social media icons are nowhere to be seen.
Not only that, but even though I have the same thing written in every page (I copy-pasted everything), the home page is the only one that's listening to the CSS.
This is my code so far:
body {
background-color: #202020 !important;
font-family: "Open Sans", sans-serif;
}
#header {
background-color: #202020;
text-align: center;
margin: 5px auto;
padding: 2px 0px;
}
.navbar {
display: flex;
justify-content: flex-end;
color: #f8f8f8;
background-color: #202020;
height: fit-content;
}
.nav-link {
flex: 1 1 auto;
padding: 5px 0;
color: #f8f8f8;
background-color: #202020;
text-align: center;
display: inline-block;
text-decoration: none;
width: -moz-fit-content;
transition: 0.2s;
}
.nav-link:hover {
background-color: #f8f8f8;
color: #202020;
}
.navbar {
position: relative;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
.navbar li {
position: relative;
padding: 10px 0 10px 28px;
text-decoration: none;
list-style-type: none;
display: flex;
justify-content: end;
}
.navbar a {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 15px;
white-space: nowrap;
transition: 0.3s;
position: relative;
text-align: center;
flex-wrap: wrap;
align-items: center;
}
a {
text-decoration: none;
color: #f8f8f8;
}
.navbar-brand {
text-decoration: none;
color: #f8f8f8;
font-size: 20px;
padding: 5px;
}
.navbar-brand:hover {
text-decoration: none;
color: #202020;
background-color: #f8f8f8;
padding: 5px;
}
.header-social-links a {
line-height: 0px;
font-size: 16px;
}
.navbar-dark .navbar-toggler {
color: #f8f8f8;
border-color: #f8f8f8;
background-color: #202020;
}
#name {
font-size: 20px;
}
<body cz-shortcut-listen="true">
<header id="header" class="fixed-top">
<nav class="navbar navbar-expand-lg fixed-top navbar order-last order-lg-0">
<div class="container-fluid d-flex justify-content-between align-items-center">
<a class="navbar-brand" href="index.html" id="name">Maria F. Loscher</a>
<button class="navbar-dark 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">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.html">home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/about.html">about me</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/portfolio.html">portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/cv.html">curriculum vitae</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/commissions-hiring.html">commissions' pricing and hiring info</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/about.html#contact">contact</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="header-social-links">
<i class="bi bi-twitter"></i>
<i class="bi bi-facebook"></i>
<i class="bi bi-instagram"></i>
<i class="bi bi-linkedin"></i>
</div>
</header>
</body>
This worked for me:
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Maria F. Loscher</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
</head>
<style>
.body {
background-color: #202020 !important;
font-family: "Open Sans", sans-serif;
}
#header {
background-color: #202020;
text-align: center;
margin: 5px auto;
}
.navbar {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
position: relative;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
.nav-link {
flex: 1 1 auto;
padding: 5px 0;
color: #f8f8f8;
background-color: #202020;
text-align: center;
display: inline-block;
text-decoration: none;
width: -moz-fit-content;
transition: 0.2s;
}
.nav-link:hover {
background-color: #f8f8f8;
color: #202020;
}
.navbar li {
position: relative;
padding: 10px 0 10px 28px;
text-decoration: none;
list-style-type: none;
display: flex;
justify-content: end;
}
.navbar a {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 15px;
white-space: nowrap;
transition: 0.3s;
position: relative;
text-align: center;
flex-wrap: wrap;
align-items: center;
}
a {
text-decoration: none;
color: #f8f8f8;
}
.navbar-brand {
text-decoration: none;
color: #f8f8f8;
font-size: 20px;
}
.navbar-brand:hover {
text-decoration: none;
color: #202020;
background-color: #f8f8f8;
}
.header-social-links a {
line-height: 0px;
font-size: 16px;
}
.navbar-dark .navbar-toggler {
color: #f8f8f8;
border-color:#f8f8f8;
background-color: #202020;
}
#name {
font-size: 20px;
}
</style>
<body cz-shortcut-listen="true">
<header id="header" class="fixed-top">
<nav class="navbar navbar-expand-lg fixed-top navbar order-last order-lg-0">
<div class="container-fluid d-flex justify-content-between align-items-center">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<a class="navbar-brand" href="index.html" id="name">Maria F. Loscher</a>
<button class="navbar-dark 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>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.html">home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/about.html">about me</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/portfolio.html">portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/cv.html">curriculum vitae</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/commissions-hiring.html">commissions' pricing and hiring info</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/about.html#contact">contact</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="header-social-links">
<i class="bi bi-twitter"></i>
<i class="bi bi-facebook"></i>
<i class="bi bi-instagram"></i>
<i class="bi bi-linkedin"></i>
</div>
</header>
</body>
I throw your navbar in the same div as the navitems
I added some css code for the navbar from here:https://www.w3schools.com/howto/howto_js_topnav.asp
I am having a slight issue trying to increase the size of my navbar brand image i have inside my main navigation. It seem like it wont go any larger the 50px. I would like it around 100px high but just cant seem to work out how to do it. I currently have it in the center of the navigation with the burger menu along side it.
Would anyone know how to achieve what i am trying to do?
HTML:
<nav class="navbar navbar-default custom-nav">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<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" href="#"></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
About <span class="caret"></span>
<ul class="dropdown-menu">
<li>History</li>
<li>Meet The Team</li>
<li>Facilities</li>
<li>Opening Times</li>
<li>Membership</li>
</ul>
</li>
<li>Diary</li>
<li>Lessons</li>
<li class="dropdown">
Events<span class="caret"></span>
<ul class="dropdown-menu">
<li>Corporate Days </li>
<li>Hens & Stags</li>
<li>Group Bookings</li>
</ul>
</li>
<li>Gallary
</li>
<li>Contact
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
CSS:
.navbar-brand {
background: url(../img/logo.png);
background-position: center;
background-repeat: no-repeat;
background-size: contain;
width: 300px;
transform: translateX(-50%);
left: 50%;
position: absolute;
padding: 0;
}
.navbar-default .navbar-toggle .icon-bar {
background-color: #fff;
}
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
.custom-nav {
color: #fff;
background: #718373;
border-radius: 0;
margin-bottom: 0;
border: 0;
}
.custom-nav .navbar-nav>li>a {
color: #fff;
margin: 0 auto;
}
.custom-nav .navbar-nav>li>a:hover,
.custom-nav .navbar-nav>li>a:focus {
color: #fff;
}
.navbar-default .navbar-toggle:focus,
.navbar-default .navbar-toggle:hover {
background: none;
}
.custom-nav .navbar-nav>.open>a,
.custom-nav .navbar-nav>.open>a:focus,
.custom-nav .navbar-nav>.open>a:hover {
color: #fff;
background: none;
}
.custom-nav .navbar-nav li {
margin: 0 auto;
text-align: center;
width: 150px;
}
.dropdown-menu {
padding: 0;
margin: 0;
background: #718373;
border: none;
box-shadow: none;
min-width: 90px;
}
.dropdown-menu li:last-child a {
margin-bottom: 10px;
}
.dropdown-menu>li>a {
display: block;
clear: both;
font-weight: normal;
color: #fff;
width: 95%;
margin: 0 auto;
text-align: center;
padding: 20px 0;
}
.dropdown-menu>li>a:focus,
.dropdown-menu>li>a:hover {
color: #fff;
text-decoration: none;
background: none;
outline: 2px solid white;
outline-offset: -2px;
}
This is how it looks at the moment
EDIT after adding
.navbar-header .navbar-brand {
height: 100px;
}
Your styles are overwritten by Bootstraps navbar styles. Use higher specificity to make your styles apply to the navbar-brand, e.g. with
.navbar-header .navbar-brand {
height: 100px;
}
This way you can overwrite the height.
.navbar-header .navbar-brand {
background: url(../img/logo.png);
background: url(//placehold.it/300x100);
background-position: center;
background-repeat: no-repeat;
background-size: contain;
height: 100px;
width: 300px;
transform: translateX(-50%);
left: 50%;
position: absolute;
padding: 0;
: #fff;
}
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
.custom-nav {
color: #fff;
background: #718373;
border-radius: 0;
margin-bottom: 0;
border: 0;
}
.custom-nav .navbar-nav>li>a {
color: #fff;
margin: 0 auto;
}
.custom-nav .navbar-nav>li>a:hover,
.custom-nav .navbar-nav>li>a:focus {
color: #fff;
}
.navbar-default .navbar-toggle:focus,
.navbar-default .navbar-toggle:hover {
background: none;
}
.custom-nav .navbar-nav>.open>a,
.custom-nav .navbar-nav>.open>a:focus,
.custom-nav .navbar-nav>.open>a:hover {
color: #fff;
background: none;
}
.custom-nav .navbar-nav li {
margin: 0 auto;
text-align: center;
width: 150px;
}
.dropdown-menu {
padding: 0;
margin: 0;
background: #718373;
border: none;
box-shadow: none;
min-width: 90px;
}
.dropdown-menu li:last-child a {
margin-bottom: 10px;
}
.dropdown-menu>li>a {
display: block;
clear: both;
font-weight: normal;
color: #fff;
width: 95%;
margin: 0 auto;
text-align: center;
padding: 20px 0;
}
.dropdown-menu>li>a:focus,
.dropdown-menu>li>a:hover {
color: #fff;
text-decoration: none;
background: none;
outline: 2px solid white;
outline-offset: -2px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default custom-nav">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<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" href="#"></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
About <span class="caret"></span>
<ul class="dropdown-menu">
<li>History
</li>
<li>Meet The Team
</li>
<li>Facilities
</li>
<li>Opening Times
</li>
<li>Membership
</li>
</ul>
</li>
<li>Diary
</li>
<li>Lessons
</li>
<li class="dropdown">
Events<span class="caret"></span>
<ul class="dropdown-menu">
<li>Corporate Days
</li>
<li>Hens & Stags
</li>
<li>Group Bookings
</li>
</ul>
</li>
<li>Gallary
</li>
<li>Contact
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>