It's very similar to this question: bootstrap4 nav not working properly which doesn't seem to be resolved.
I was moving my app from Angular 4 to Angular 5, in the process of "npm update", I moved to "bootstrap": "4.0.0-beta.2", the NavBar Brand is now right aligned. And no matter how wide screen is, the items are collapsed.
To sort out this issue. I actually did ng new nav-app. So brand new application is created.
I then intalled Bootstrap, Jquery, Popper as mentioned in this article: http://colinstodd.com/blog/post/how-to-install-bootstrap-4-beta-in-angular-4-as-a-dependency
here is my angular-cli.json:
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
"scripts": [
"../node_modules/jquery/jquery.min.js",
"../node_modules/popper.js/dist/umd/popper.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.bundle.js"
],
And I put the Nav Bar example in the official Bootstrap website: https://v4-alpha.getbootstrap.com/components/navbar/ into app.component.html
<nav class="navbar navbar-toggleable-md navbar-dark bg-dark">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<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="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
And the result looks like this:
1. The toggle (hamburger icon) works when I click on it. But the position is reversed, and doesn't matter how wide the browser window is, the hamburger icon doesn't expand.
I think the bootstrap.css is definitely working fine, since I made a button, and it has the proper bootstrap colors.
Question: how do I control when the hamburger icon appears or not? (when screen is wide, the Nav items should be shown without hamburger icon.)
And can someone explain what happened with the Beta Bootstrap? My code used to work with previous version of Bootstrap, including 4 Alpha.
My production code Nav Bar displays all Nav items correctly when screen is wide enough to show all. And it collapse at the right time. I'm trying to figure out is this a Angular 5 issue or actually Boostrap decided to go from 4 Alpha to 4 Beta and decided to completed change their css class positions.
The navbar-expand-* class is what you are missing.
Try adding navbar-expand-lg.
The documentation is here:
https://getbootstrap.com/docs/4.0/components/navbar/
The alpha version is hopelessly outdated!
P.S. Bootstrap 4 beta 3 is the most recent version of Bootstrap 4. The next release will be Bootstrap 4 final.
Related
I am copy and pasting the bootstrap documentation navbar https://getbootstrap.com/docs/5.0/components/navbar/ directly into a react component:
export default function Navbar() {
return (
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">
Navbar
</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" id="navbarSupportedContent">
<ul class="navbar-nav me-auto">
<li class="nav-item active">
<a
class="nav-link"
href="#"
data-bs-toggle="collapse"
data-bs-target=".navbar-collapse.show"
>
Home
</a>
</li>
<li class="nav-item">
<a
class="nav-link"
href="#"
data-bs-toggle="collapse"
data-bs-target=".navbar-collapse.show"
>
Link
</a>
</li>
<li class="nav-item">
<a
class="nav-link disabled"
href="#"
data-bs-toggle="collapse"
data-bs-target=".navbar-collapse.show"
>
Disabled
</a>
</li>
</ul>
</div>
</div>
</nav>
);
}
The Navbar displays correctly when previewed and expands when clicked correctly, but when I click the toggle again it does not collapse. When inspecting the element and clicking I see this change:
<div class="collapse **collapsing**" id="navbarSupportedContent">
but nothing changes on my page. I have bootstrap 5.2 installed locally and am able to use other bootstrap features on my page. Other collapses work fine as well. What am I missing?
Bootstrap depends on its JS for some functionality. Have you imported the JS bundle (preferably in your global app file)? If not, please do. If you have, then consider using ReactStrap which is optimized for react.
https://reactstrap.github.io/
Make sure that you already have imported all the dependencies. Some components require JavaScript plugins and Popper to work properly.
Read more about this: https://getbootstrap.com/docs/5.0/getting-started/introduction/
Also https://getbootstrap.com/docs/5.0/getting-started/introduction/#components for more specific components that require those plugins.
This question already has answers here:
Bootstrap 4 Navbar doesnt collapse in Angular4
(4 answers)
Closed 3 years ago.
I am using this code example to implement a collapsible navbar using Bootstrap 4 in an Angular project.
Bootstrap was installed using npm along with Popper and jQuery. Versions:
angular/core: 8.2.5
angular/cli: 8.3.3
bootstrap: 4.3.1
popper: 1.0.1
popper.js: 1.15.0
jquery: 3.4.1
As shown below in the screenshot, decreasing the window size collapses the navbar and shows the hamburger button. However the hamburger button does nothing No errors are logged in the console.
Here is my code for the navigation:
<nav class="navbar navbar-expand-md navbar-light bg-light">
<a class="navbar-brand" href="#">chumiest bucket</a>
<button class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#collapsingNavbar"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsingNavbar">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
The answers I've come across all stem from not having the proper CDN link (which I'm not using); the method I'm going with may not be correct.
What Worked
add Popper, Bootstrap and jQuery JavaScript files to angular.json "scripts" list like this:
...
"scripts": [
"./node_modules/jquery/dist/jquery.js",
"./node_modules/popper.js/dist/umd/popper.js",
"./node_modules/bootstrap/dist/js/bootstrap.js"
]
I am working on an Angular application and have installed Bootstrap using Bower. On my index.html file I have the bootstrap js and css files, both minified.
When I view my app in a browser the navbar is not displaying as expected. Here is the code for the navigation bar I have on my page.
<nav class="navbar navbar-inverse bg-inverse navbar-expand-md fixed-top">
<a class="navbar-brand" href="home">Akeva</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="companies">Companies</a>
</li>
</ul>
</div>
The CSS adds the background colour and the menu items align horizontally but the rest of the navigation does not look how it should.
Here is how the navigation is appearing:
how the menu is display
Any ideas on why the Bootstrap nav is not appearing as expected?
I am not very adept at styling websites and have trouble with css and responsive design. As such, at the suggestion of a co-worker, I've decided to give the Bootstrap toolkit a try and so far I've been very happy with it. However, I am having trouble understanding a few things about the navbar components of the kit and so far have been unsuccessful in customizing this portion of the templates.
One of my sources of confusion stems from the pervasive inclusion of a toggleable button for collapsing the navigation bar. It seems like no matter what example they show of the navigation bar, they've included the collapse classes and toggle button, even where that button doesn't appear to be displayed anywhere and the navigation bar is not collapsed. For example, take a look at the following link: http://getbootstrap.com/examples/navbar-fixed-top/
If you view the source here, there you see the button and the collapse classes, but the navbar is missing said button and it is not collapsed. When I view the CSS I do see that it has display: none; specified, but then why include it at all?
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Default</li>
<li>Static top</li>
<li class="active">Fixed top <span class="sr-only">(current)</span></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
Finally, I believe this issue is interrelated to the second issue I'm having, which is, I am trying to right justify the links of my customized navbar with the navbar-right class, but when I do so, the links don't move to the right. Does this have something to do with my removal of the toggle button and collapse classes? Here is my attempt which has failed miserably. I am using the base jumbotron template and have included the jumbotron and min bootstrap css files. The jumbotron css file is very minimal and only includes some body stylings for a margin and a color, I believe. I can't see where that would be preventing my navigation links from showing up on the side.
Instead, the image appears on the left, and the links appear just below it, with no styling whatsoever, just a jammed together list of links. The dropdown does not work because I was experimenting with a different method used on the angular site by specifying the uib-dropdown so I should mention that - the dropdown portion was working when I had the bootstrap classes and attributes specified.
For a jsfiddle example of what is happening when I attempt to get the links to show up on the right: https://jsfiddle.net/1jehsp5r/
In fact, I have yet to find a single working example of the right alignment in the navbar. I have re-done this code about 10 times now and not a single combination of classes and divs have yeilded a simple fixed top navigation bar with an element on the left and a set of links on the right. Take this tutorial for example: https://www.tutorialspoint.com/bootstrap/bootstrap_navbar.htm - They have a screenshot of it working, but when you click the "try-it" button and it loads into an interactive screen, their OWN example doesn't even work right. Everything aligns on the left, which is exactly what I am experiencing.
Can anyone show me the right way of simply making a simple navigation bar similar to the one here: https://angularjs.org/
For the collapse button, it is set to appear in small screen for most of the cases. It's there for responsiveness (or the art of display well on all screen size).
Here is an example of collapse button : Bootstrap navbar external-content
To align items on the right side of the row, you could use the ml-auto (margin-left: auto;) class on the <ul> element.
Here is an example of a bootstrap navbar with links align on the right side.
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<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="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
Hope it helps.
EDIT :
Those examples was build for Bootstrap 4 alpha 6.
How can I get always display the mobile menu button no matter screen size? I do not want the links to appear until a person clicks the mobile button. Thank you!
I realize there is a post here on Bootstrap 3, however it does not work with Bootstrap 4. Will you please advise?
Update Bootstrap 4.1.x
Exclude the navbar-expand* class.
As of beta, the navbar-toggleable-* class was replaced with navbar-expand-*, but now everythings moves up a tier. Since the default state of the navbar is always collapsed/mobile (xs) you'd simply exclude the navbar-expand-* class so that the menu is always collapsed on all tiers.
Beta demo: https://www.codeply.com/go/HiMQd9taEd
Bootstrap 4.1.3: https://www.codeply.com/go/ugmj6XKY79
Original Answer (Bootstrap 4 alpha)
In Bootstrap 4 the navbar is very different than 3.x, and it is always collapsed unless overriden by one of the navbar-toggleable-* classes. You just need to make sure your navbar doesn't include navbar-toggleable-*.
<nav class="navbar navbar-fixed-top">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#collapsingNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<div class="navbar-collapse collapse" id="collapsingNavbar">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Wow</a>
</li>
</ul>
</div>
</nav>
Alpha demo: http://www.codeply.com/go/LN6szcJO53