Bootstrap navbar alignment issues - css

In Bootstrap 4 within the toggler hamburger menu is active clicking it will show HomeAbout on the one line, not sure why these aren't on separate lines.
Code:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
Example
<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 flex-row ml-md-auto d-md-flex">
<li class="nav-item">
Home
</li>
<li class="nav-item dropdown">
About
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Feedback</a>
</div>
</li>
</ul>
</div>
</nav>
Fiddle: https://jsfiddle.net/StoogeMate/qts6gamk/
There's no obvious answer I've been able to find through using Bootstrap itself particularly for the first problem without overriding the .css itself and applying !important tags
Does Bootstrap have this capability?

By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. Add .dropdown-menu-right to a .dropdown-menu to right align the dropdown menu.
https://getbootstrap.com/docs/4.0/components/dropdowns/#menu-alignment
Remove dropdown from the About menu item
Wrap the About menu item in a div.btn-group
Use dropdown-menu-right on div.dropdown-menu
<li class="nav-item">
<div class="btn-group">
About
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Feedback</a>
</div>
</div>
</li>
🎁
Remove flex-row to show the menu items on two lines.
<ul class="navbar-nav ml-md-auto d-md-flex">
----
</ul>

Related

Dropdown Menu in .Net 6 Web App does not work

Working on a .Net 6 Web App for a client and have a problem with the dropdown code that I have actually copied partially from Bootstrap web page. I have copied the entire code from bootstrap web page without any modification and it does not work. It behaves like a normal link-item even though it has all characteristics of a dropdown menu. I have also tried to move the nav bar to the top, but it uses a 150 px margin from the top and I cannot find any css code for this behavior. Any hints will be very much appreciated.
<header >
<nav class="navbar navbar-expand-lg navbar-light border-bottom">
<div id="navigation" class="container-fluid">
<a class="navbar-brand" asp-area="" asp-page="/Index"><img id="logo" src="/img/logo.png" height="102" width="95"/></a>
<button
class="navbar-toggler"
type="button"
data-mdb-toggle="collapse"
data-mdb-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">
<a
class="nav-link dropdown-toggle"
href="#"
id="navbarDropdown"
role="button"
data-mdb-toggle="dropdown"
aria-expanded="false"
>
Company Name
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#"><span style="color:white; font-family:Montserrat;">Pictures</span></a></li>
<li><a class="dropdown-item" href="#"><span style="color:white; font-family:Montserrat;">Videos</span></a></li>
<li><a class="dropdown-item" asp-area="" asp-page="/Privacy"><span style="color:white; font-family:Montserrat;">Privacy</span></a></li>
</ul>
</div>
</div>
</nav>
I copied the entire nav bar code from bootstrap and it still does not work.

Align nav-bar to the right using bootstrap

I'm trying to align the navbar components to the right. The code is given below. I tried with
ml-auto but it's not giving the desired result. The result that I'm getting is attached below.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<header class="bg-info">
<div class="row text-white">
<div class="col-md-6 col-9 p-3 pl-5">
<h2>Header</h2>
</div>
<div class="col-md-6 col-3 my-auto ml-auto">
<nav class="navbar navbar-expand-lg navbar-light">
<button class="navbar-toggler ml-auto" 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">
<!-- me-auto mb-2 mb-lg-0 -->
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active text-white" aria-current="page" href="#">Home</a
>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Know More</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Actions</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Contact Us</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
</header>
Result
I want the home, know more, etc.. content to be right-aligned. I have divided it initially into two columns. Then gave the second one the ml-auto class. What's the issue here?
I checked safari, chrome, firefox and the snippet checker in StackOverflow.
All are showing the correct styling and not what you screenshot-ed. Maybe you have an extension that is injecting some sort of custom CSS? Or you don't have the bootstrap file loaded properly?
Your font also seems a bit off in the screenshot.
What my Chrome looks like :
Could be very easy. Remove all ml-auto's then use d-flex to justify-content-end (right). justify-content-start would be the left. But.... As somebody else pointed out. When I try your code - Your menu is on the right hand side and Header on the left as required.
<nav class="navbar navbar-expand-lg navbar-light d-flex justify-content-end">

Navbar not sizing to fit mobile screen

Here is my site https://cleveroscar.github.io./ I want to make my navbar fit the mobile screen to be usable, but when tested on my iphone the navbar is super tiny, check on dev tools to see what I am talking about, here is the code below, I am using CanJS to support my view and bootstrap 4 for my css frame work.
<div><!-- nav starting div -->
<nav class="navbar navbar-expand-lg navbar-dark" id="navbg">
<a class="navbar-brand" href="https://cleveroscar.github.io./">Clever Oscar</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">
<li class="nav-item active ">
<a class="nav-link" href="#">About <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Projects</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="https://github.com/CleverOscar">Github</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="https://twitter.com/CleverOscarDev">Twitter</a>
</li>
</ul>
</div>
</nav>
</div> <!-- nav ending div -->
I also have a git repository to look at the code if anyone wants too
what you need is a viewport metatag, so viewport scales with your screensize<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>

Bootstrap4 media query directly taken mobile view even file opening on laptop

i'm using bootstrap 4 on my new project and my laptop Touch + Mouse enabled windows when i tried to use bootstrap its automatically showing mobile format in desktop. how to solve this? below i attached screenshot
Note : Bootstrap 3 is working fine. this problem only on bootstrap4
My Code:
<header>
<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">
<img src="images/logo.png" class="d-inline-block align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav mr-auto 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="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<button class="btn btn-outline-success" type="button">Main button</button>
</form>
</div>
</nav>
</header>
You need to use the correct HTML as stated in the documentation of bootstrap
Navbars require a wrapping .navbar with .navbar-expand{-sm|-md|-lg|-xl} for responsive collapsing
You neglected this class, so it is always collapsed.
It is not enough to just change the CSS from bootstrap 3 to 4 you also have to change the markup quite a bit.

ng-sidebar to create a sidebar that pushes content to the right

I am using ng-sidebar to animate and implement the collapsable sidebar on smaller mobile screens.
This is my first time using Angular so I apologize if the question is simple for everyone else.
I have installed using npm install ng-sidebar and tried the working demo, but I have difficulty adjusting it to my needs.
In my app.component.html I have this code taken from the demo :
<ng-sidebar-container>
<ng-sidebar
[(opened)]="_opened"
[mode]="_MODES[_modeNum]"
[closeOnClickOutside]="_closeOnClickOutside"
[closeOnClickBackdrop]="_closeOnClickBackdrop"
[showBackdrop]="_showBackdrop"
[animate]="_animate">
<button (click)="_toggleOpened()">Close sidebar</button>
<p><a closeSidebar>This will close the sidebar too</a></p>
<hr>
<ul class="nav nav-pills flex-column">
<li class="nav-item collapsed side" data-toggle="collapse" data-target="#home">
<a class="nav-link" routerLinkActive="active" routerLink="/home" [routerLinkActiveOptions]="{exact: true}">Home</a>
</li>
<ul class="sub-menu collapse" id="home">
<li class="nav-item list-unstyled"> <a class="nav-link" routerLinkActive="active" routerLink="/home/submenu">Submenu</a>
</li>
<li class="nav-item list-unstyled">
<a class="nav-link" routerLinkActive="active" routerLink="/home/submenu2">Submenu2</a>
</li>
<li class="nav-item side">
<a class="nav-link" routerLinkActive="active" routerLink="/secondMenu"MenuItem>/a>
</li>
</ul>
</ng-sidebar>
<div ng-sidebar-content>
<header class="demo-header">
<button class="navbar-toggler " type="button" (click)="_toggleOpened()" data-toggle="collapse" data-target="#sidebar" aria-controls="navbarsExampleDefault"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
<span>ng-sidebar</span>
</header>
<section class="demo-contents">
<router-outlet></router-outlet>
</section>
</div>
What I do not understand is, how to put a :
<button class="navbar-toggler " type="button" data-toggle="collapse" data-target="#sidebar" aria-controls="navbarsExampleDefault"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
That when clicked, called
_toggleOpened() and [mode]="_MODES[_modeNum]"
mode should be push
Example link
And have it on the top bar as in the example. Because no css style is applied on my document when trying the demo.
How do I make that button and sidebar to only push the content as in the link when clicking mode-push, and also add transparent background ?
So the button should push the content, add background and when clicking anywhere outside on the screen to be closed. ?
I'm very sorry again, I just need a simple layout to help me get started :| To understand it
Thank you in advance!

Resources