Angular Bootstrap 4 Navbar won't toggle and problems with navbar-dark - html

When I have a small screen width and I'm trying to click the hamburger to toggle the navigation - nothing happens. I've already tried to solve the problem with already asked questions, but I haven't been able to find my error.
Additionally as soon as I remove navbar-dark the hamburger vanishes - having this class added to the object again, changes the color of the navbar to white, which I don't want it to.
<nav class="navbar navbar-dark navbar-expand-lg">
<div class="container-fluid px-0">
<div class="row w-100">
<div class="col-2">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="col-10">
<div class="collapse justify-content-end navbar-collapse" id="navbarTogglerDemo03">
<ul class="navbar-nav mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Book Me</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
Angular.json:
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css",
"node_modules/aos/dist/aos.css"
],
"scripts": [
"node_modules/popper.js/dist/popper.min.js",
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
],
Package.json:
"dependencies": {
"#angular/animations": "^7.2.11",
"#angular/cdk": "^7.3.6",
"#angular/common": "~7.2.0",
"#angular/compiler": "~7.2.0",
"#angular/core": "~7.2.0",
"#angular/fire": "^5.1.1",
"#angular/forms": "~7.2.0",
"#angular/material": "^7.3.6",
"#angular/platform-browser": "~7.2.0",
"#angular/platform-browser-dynamic": "~7.2.0",
"#angular/router": "~7.2.0",
"aos": "^2.3.4",
"bootstrap": "^4.3.1",
"core-js": "^2.5.4",
"firebase": "^5.8.5",
"jquery": "^3.3.1",
"ng-recaptcha": "^4.2.1",
"popper.js": "^1.14.7",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},

You have a few issues:
install bootstrap to angular 6+ as here
Add bg-dark class to <nav>
use this example to demo bootstrap behavior in angular
See here working code
HTML
<nav class="navbar navbar-dark bg-dark navbar-expand-lg">
<div class="container-fluid px-0">
<div class="row w-100">
<div class="col-2">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation" (click)="isShown = !isShown" >
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="col-10">
<div class="collapse justify-content-end navbar-collapse" [ngClass]="{ 'show': isShown }" id="navbarTogglerDemo03">
<ul class="navbar-nav mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#" (click)="isShown = false" >Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" (click)="isShown = false" >About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" (click)="isShown = false" >Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" (click)="isShown = false" >Book Me</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
TS
isShown:boolean=false;

Related

I am working with Bootstrap 5.2 and my mobile menu will not shut when toggled I would appreciate another set of eyes on the code. Thanks in advance

<body style="background-image: url('/img/smush.png');background-size:cover;background-repeat:no-repeat">
<div class="container">
<header class="pt-2">
<nav class="navbar navbar-expand-lg bg-none fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#">Slightly Sophisticated</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse bg-none p-2 d-flex flex-column justify-content-end" id="navbarSupportedContent">
<ul class="nav">
<li class="nav-item">
<a class="nav-link active text-dark" aria-current="page" href="#services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#mission">About</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#work">Work</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#testimonials">Testimonials</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#contact">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
I was expecting the toggle to work correctly on mobile. Not sure why it is not working right now, I feel like i looked through it thoroughly but its obviously not the case if i am asking the question here lol

Logo on navbar is not displaying

I am creating a website with the react.js framework and am very new to it. I am trying to get my logo on the bootstrap navbar. However, it seems that the image is not displaying.
This is the code for my navigation bar
<nav className="navbar navbar-expand-lg navbar-dark fixed-top bg-dark" id="mainNav">
<div className="container">
<a className="navbar-brand js-scroll-trigger" href="#page-top"><img src="navbar-logo.svg" alt="" /></a>
<button className="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i className="fas fa-bars ml-1"></i>
</button>
<div className="collapse navbar-collapse" id="navbarResponsive">
<ul className="navbar-nav text-uppercase ml-auto">
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#services">Services</a></li>
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#portfolio">Facilities</a></li>
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#about">About</a></li>
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#team">Executives</a></li>
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
You need to import image. You can't add src like this in react:
Do this:
Import logo
import myLogo from 'navbar-logo.svg';
Add logo src:
<img src={myLogo} alt="" />
...your rest of code
If you want to show logo you must use html tag :
<!DOCTYPE html>
<html>
<head>
<link media rel="icon" href="##your logo url" type="image/png" />
</head>
<body>
##content
</body>
</html>
Try like this
.logo {
height:25px;
}
<nav className="navbar navbar-expand-lg navbar-dark fixed-top bg-dark" id="mainNav">
<div className="container">
<a className="navbar-brand js-scroll-trigger" href="#page-top"><img src="https://i.picsum.photos/id/1029/4887/2759.jpg?hmac=uMSExsgG8_PWwP9he9Y0LQ4bFDLlij7voa9lU9KMXDE" alt="" class="logo"/></a>
<button className="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i className="fas fa-bars ml-1"></i>
</button>
<div className="collapse navbar-collapse" id="navbarResponsive">
<ul className="navbar-nav text-uppercase ml-auto">
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#services">Services</a></li>
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#portfolio">Facilities</a></li>
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#about">About</a></li>
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#team">Executives</a></li>
<li className="nav-item"><a className="nav-link js-scroll-trigger" href="#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
if you want to use a local image, import from your project and pass to src
import Logo from './path_name';
pass like this.
<img src={Logo} alt="" class="logo"/>

Trying to center navbar links bootstrap 4 [duplicate]

This question already has an answer here:
Center Navbar links without brand pushing it to the right in Bootstrap 4?
(1 answer)
Closed 3 years ago.
Im Trying to center my links right under the h1, but nothing works. Here's what i have right now, i would love any help or pointers!
This is my h1-tag
<div class="container-fluid p-5 bg-success header-body text-center">
<h1 id="high-credit-top-text">
<a class="text-white" style="font-family: 'Lexend Deca', sans-serif;" href="hogkostnadskredit.php">Playaround.se</a>
</h1>
<nav class="navbar navbar-expand-lg navbar-light bg-success">
<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">
<div class="container justify-content-center">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link text-white" href="playaround.php"><i class="fas fa-home"></i></a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="nyheter.php">Nyheter</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="information.php">Infomartion</a>
</li>
</ul>
</div>
</div>
</nav>
If you are trying to center the .nav-item links horizontally, then add the bootstrap class justify-content-center to the ul tag with class navbar-nav
<ul class="navbar-nav justify-content-center">
<li class="nav-item active">
<a class="nav-link text-white" href="playaround.php"><i class="fas fa-home"></i></a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="nyheter.php">Nyheter</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="information.php">Infomartion</a>
</li>
</ul>
Example
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="container-fluid p-5 bg-success header-body text-center">
<h1 id="high-credit-top-text">
<a class="text-white" style="font-family: 'Lexend Deca', sans-serif;" href="hogkostnadskredit.php">Playaround.se</a>
</h1>
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-success">
<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">
<div class="container justify-content-center">
<ul class="navbar-nav justify-content-center">
<li class="nav-item active">
<a class="nav-link text-white" href="playaround.php"><i class="fas fa-home"></i></a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="nyheter.php">Nyheter</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="information.php">Infomartion</a>
</li>
</ul>
</div>
</div>
</nav>

Collapse not working in Angular navbar for mobile

I have an Angular project without Jquery.
I want to have a navbar with mdbootstrap, But when I write mdbootstrap code in my html, collapse does not work.
Here is my html content.
<header>
<nav class="navbar navbar-expand-lg navbar-dark primary-color">
<a class="navbar-brand" href="#">Navbar</a>
<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">
<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">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
</header>
The documentation is not very user-friendly, but still goes over the basic navbar... the classes use tell it when to move from hanburger menu to expanded form (navbar-expand-lg in our case); the rest is just dummy text in the example below.
relevant HTML:
<mdb-navbar SideClass="navbar navbar-expand-lg navbar-dark pink ie-nav" [containerInside]="false">
<mdb-navbar-brand>
<a class="logo navbar-brand" href="#"><strong>Navbar</strong></a>
</mdb-navbar-brand>
<links>
<ul class="navbar-nav mr-auto">
<li class="nav-item active waves-light" mdbWavesEffect>
<a class="nav-link">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item waves-light" mdbWavesEffect>
<a class="nav-link">Features</a>
</li>
<li class="nav-item waves-light" mdbWavesEffect>
<a class="nav-link">Pricing</a>
</li>
<li class="nav-item waves-light" mdbWavesEffect>
<a class="nav-link">Opinions</a>
</li>
</ul>
<ul class="navbar-nav nav-flex-icons">
<li class="nav-item waves-light" mdbWavesEffect>
<a class="nav-link"><mdb-icon fab icon="facebook-f"></mdb-icon></a>
</li>
<li class="nav-item waves-light" mdbWavesEffect>
<a class="nav-link"><mdb-icon fab icon="twitter"></mdb-icon></a>
</li>
<li class="nav-item waves-light" mdbWavesEffect>
<a class="nav-link"><mdb-icon fab icon="instagram"></mdb-icon></a>
</li>
</ul>
</links>
</mdb-navbar>
relevant CSS:
.navbar-toggler-icon{ border:2px solid red;}
.navbar-brand, .nav-link{color:red !important;}
complete working stackblitz here
I'm posting the best way using Angular Material library to make sidenav as main nav of your application. You no need to install any other librarys then Angular Material
npm i --save #angular/material #angular/cdk #angular/animations
ng add #angular/material
Here is a code: https://stackblitz.com/edit/angular-c8gpuh
Here is an video tutorial: https://www.youtube.com/watch?v=Q6qhzG7mObU
And in your app.component.html:
<sidenav-autosize-example>
<router-outlet></router-outlet>
</sidenav-autosize-example>
And remember to import nessesery modules to your project:
import { NgModule } from '#angular/core';
import { MatSidenavModule, MatToolbarModule, MatButtonModule, MatIconModule, MatProgressBarModule } from '#angular/material';
#NgModule({
declarations: [],
imports: [
MatSidenavModule,
// MatToolbarModule,
MatButtonModule,
MatIconModule,
// MatProgressBarModule,
],
exports: [
MatSidenavModule,
// MatToolbarModule,
MatButtonModule,
MatIconModule,
// MatProgressBarModule,
],
})
export class MaterialModule { }

adding a header to my navigation

I am trying to add a header as part of my navigation but below it like this:
I have tried adding another row using bootstrap however it just comes out like this:
this is my code:
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
<a class="navbar-brand js-scroll-trigger" href="#page-top">Bunk.</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fa fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#tenant">TENANT</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#landlord">LANDLORD</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#bunkfaqs">BUNK FAQs</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#blog">BLOG</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#team">TEAM</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#login">LOG IN</a>
</li>
</ul>
</div>
<div class="row">
<header id="header">
<div class="container">
<div class="row">
<h2> Tenants </h2>
</div>
</div>
</header>
</div>
any suggestions?
Read more about Bootstrap's Navbar and grid.
The navbar should only contain supported content.
The header shouldn't be in the navbar, put it below.
.container shouldn't be nested in other .containers.
.row is meant to contain only col-*.
Demo on Codeply
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top" id="mainNav">
<a class="navbar-brand js-scroll-trigger" href="#page-top">Bunk.</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fa fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#tenant">TENANT</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#landlord">LANDLORD</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#bunkfaqs">BUNK FAQs</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#blog">BLOG</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#team">TEAM</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#login">LOG IN</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="container-fluid bg-light">
<header id="header" class="d-flex align-items-center">
<h2 class="mx-auto">Tenants</h2>
</header>
</div>