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

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!

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.

Bootstrap Navbar collapse toggle not working when directly copy and pasted from documentation

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.

Bootstrap navbar alignment issues

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>

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.

Resources