Group items into dropdown menu when collapsed - css

I have just found this type of collapse navbar from a site, all menu items grouped into a dropdown menu and positioned right, its different from usual bootstrap collapse navbar
Sorry for having not enough reputations to post image
https://i.imgur.com/EFzI7hl.png
https://i.imgur.com/DhS4BlZ.png
I have tried many suggestions but it didnt work exactly like what theirs did, the result is always full vertical dropdown menu
https://i.imgur.com/s5O7cSD.png
My code
<nav class="navbar fixed-top navbar-expand-lg py-0" style="background-color: #0d47a1;">
<a class="navbar-brand" href="/dashboard/">
<img src="/images/logo.webp" width="40" height="40" alt="">
</a>
<button class="navbar-toggler navbar-dark" 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">
<li class="nav-item px-2">
<a class="nav-link" href="#">Shop Manager</a>
</li>
<li class="nav-item px-2">
<a class="nav-link" href="#">Customer Care</a>
</li>
<li class="nav-item px-2">
<a class="nav-link" href="#">Messenger Order</a>
</li>
</ul>
</div>
</nav>

You'll need to add a little custom css to get the menu smaller that full width:
.navbar-collapse {
position: absolute;
right: 0;
top: 40px;
background-color: #333;
}
#media (min-width: 768px) {
.navbar-collapse {
background-color: transparent;
position: initial; /* Using 'initial' here rather than specificing 'relative'.*/
}
}
Here is a fiddle showing it working. You can customize it form there to get it looking like the examples you provided, but that's the rough idea.

Related

Centering and styling Bootstrap 4 navbar with custom color and spacing

New to frontend development and trying to get acquainted with Twitter Bootstrap 4 and CSS with a mock nonprofit page. I really like how the Auth0.com header nav looks and I'm trying to replicate it with my own logo, colors and link text.
I have created a jsFiddle capturing my best attempt but essentially the code I have is as follows:
Excerpt from template.html -- see jsFiddle for full:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark" style="margin:24px 0;">
<a class="navbar-brand" href="javascript:void(0)">
<img src="https://raw.githubusercontent.com/bitbythecron/bootstrap-troubleshooting/main/dummy-logo.png" class="img-fluid mainlogo" alt="Responsive image">
</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navb">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navb">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Help</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Volunteer</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Find</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Support</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Always</a>
</li>
<li class="nav-item">
<a class="nav-link red-button" href="javascript:void(0)">WATCH DEMO</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Sign In</a>
</li>
<li class="nav-item">
<a class="nav-link bordered" href="javascript:void(0)">Sign Up</a>
</li>
</ul>
</div>
</nav>
main.css:
html, body {
height: 100%;
}
.bordered {
border-radius: 5px;
border: 1px solid white;
}
.red-button {
border-radius: 5px;
border: 1px solid #A81E30;
background-color: #A81E30;
color: beige;
}
.mainlogo {
width: 35%;
}
When this runs in the browser, I get:
Several things here:
above the navbar there is about ~10px of whitespace, and I'd like there to be none; I tried setting <html>'s padding: 0px but that does not seem to work
the navbar background color is the BS4 default dark gray, but I'd like it to be the same color as the dark blue on my logo (#001A31)
I would like to remove all padding from the navbar so that the height of the navbar is the same height as the logo
just like the Auth0 navbar, I would like the header navbar to centered but with extra spacing between the logo and the first link ("About") and also the same extra space between the last red-button link ("WATCH DEMO") and the "Sign In" link
So I ask: what changes do I need to make to my HTML/CSS to accomplish my mock page's navbar looking like the Auth0 one, and how do I do all this while keeping the code responsive?
You have a style="margin:24px 0;" into your <nav> tag.
Placements in css acts like a clock. I mean, in order :
Top
Right
Bottom
Left
Result : margin : top right bottom left;
Or by pairs :
Top & bottom
Left & right
Result : margin : top&bottom left&right;
So your style="margin:24px 0;" should be removed, or interverting 24px with 0.
Because you are actually saying :
Margin Top and Bottom = 24px
Margin Left and Right = 0px
PS: It is a bad practice to add style directly in HTML. For testing purposes, I suggest you to use your browser console, because you can change css properties for each elements, and see what happens.
Hope this will help.

Navbar: when I fixed the navbar to the top, my components are also fixed to the top

I work on a personnal project with Angular. I want to have a top fixed navbar to write "fixed-top" in <nav>. The navbar is fixed but the probleme is that my components are also fixed to the top which is a big issue that I don't know how to resolve.
Has you can see in my screen, my component movie list is also fixed to the top so the top of the component is hide by the navbar. It is that probleme with all components/pages.
[This is a screen of my app.]1
This is my navbar template
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">
<img src="../../assets/logo1.png" alt="">
</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 ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Search
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" routerLinkActive="active" routerLink="search/movie">Movie</a>
<a class="dropdown-item" routerLinkActive="active" routerLink="search/tv-show">Tv Show</a>
</div>
</li>
<li class="nav-item" routerLinkActive="active">
<a class="nav-link" routerLink="movies">Movies</a>
</li>
<li class="nav-item" routerLinkActive="active">
<a class="nav-link"routerLink="tv-shows">Tv Shows</a>
</li>
</ul>
</div>
</nav>
This is the css
nav {
-webkit-box-shadow: 0px 5px 4px -1px rgba(173,161,173,1);
-moz-box-shadow: 0px 5px 4px -1px rgba(173,161,173,1);
box-shadow: 0px 5px 4px -1px rgba(173,161,173,1);
height: 60px;
width: 100%;
}
This is my app component calling the navbar
<app-header></app-header>
<router-outlet></router-outlet>
If you have some idea please help me.
Thanks
Here is the problem:
<nav class=". . . fixed-top . . .">
You have specified the fixed-top class. That implies that navbar will overlap beneath contents.
You could try removing that class. Or, if you want that specific class, try adding a padding: body { padding-top: 80px; } (80px or what you find it more confortable for web content shown).

Bootstrap 4: How to create a center vertical scrollable <div> using Bootstrap 4

base on my question, Basically I want to make my webpage like below:
The red box means that the div that can scrollable and the div size is according to the content size. Meanwhile, The main background (that man)and the navbar is fixed and no scrollable.
Below is my current code:
<body id="header">
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: black;">
<a class="navbar-brand" style = "font-weight: 600; font-family: Arial, Helvetica, sans-serif;" href="#">Dr. Lim Wee Chai</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" style = "font-weight: 600; font-family: Arial;" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" style = "font-weight: 500;" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" style = "font-weight: 500;" href="#">Philosophies & Values</a>
</li>
<li class="nav-item">
<a class="nav-link" style = "font-weight: 500;" href="#">Lifestyle</a>
</li>
<li class="nav-item">
<a class="nav-link" style = "font-weight: 500;" href="#">Top Glove</a>
</li>
<li class="nav-item">
<a class="nav-link" style = "font-weight: 500;" href="#">Future Vision</a>
</li>
<li class="nav-item">
<a class="nav-link" style = "font-weight: 500;" href="#">Videos</a>
</li>
</ul>
</div>
</nav>
<br>
</body>
Can anyone help me to solve this?
In CSS3, the flex properties can be usefull to achieve this. Bootstrap 4 makes great use of this in the flex utility classes. To assemble this setup, the simplest form I've found so far:
<div class="container d-flex h-100">
<div class="my-component d-flex mx-auto align-self-center flex-column">
<!-- some scrollable content -->
</div>
</div>
This is demonstrated in this fiddle.
To explain all these classes let's break it down:
Make sure html, body have height: 100%;. This is required to generate a full height body. In turn the browser can now use this height to vertically center content
.container or .container-fluid with .d-flex and .h-100 will make use of this body height to also stretch over the height of the screen.
.my-component now has a height: 50vh and width: 50vw; which is viewport height and -width and makes this component responsive. Also overflow-y: auto; to make it scrollable. Feel free to adjust this to your liking with media queries and so on.
It has also .d-flex to enable .mx-auto (horizontal center), .align-self-center (vertical center) and .flex-column to align the content properly
None of these utility classes can be omitted as they all work together.
Hopefully this is like you requested as the content of your "wrapper" isn't clear from the question.

Need help adding background color to drop-down menu on Bootstrap theme

EDIT:
I resized the drop-down menu bar, removed the borders & added a box-shadow. The drop-down button is on the right side when clicked the menu opens underneath the site title on the left, here's the updated code & picture of update:
enter image description here
HTML:
<body id="page-top">
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light fixed-top py-3" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="#page-top">My Site</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">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto my-2 my-lg-0">
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#portfolio">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#contact">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
CSS:
#media screen and (max-width:991.98px) {
.navbar-nav{
background-color: #f0ede8;
height: 200px;
width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
float:left;
}
.navbar-nav .nav-item{
text-align: center
}
}
Thanks again for your help!
I'm customizing a Bootstrap theme and would like to keep my navbar transparent but have the drop-down menu have a background color when it's resized to a smaller device. I tried altering the media queries but can't seem to figure this out. I'm still trying to get the hang of Bootstrap. I've attached two screenshots of my site as reference.The first one is how the drop-down menu currently looks. The second one is how I'd like for the drop-down menu to look.
Thank you!
HTML
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<body id="page-top">
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light fixed-top py-3" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="#page-top">My Site</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">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto my-2 my-lg-0">
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#portfolio">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#contact">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
if u want the menu size in half and positioned it under the title,
i just added a little code from #Shanice Morgan
#media screen and (max-width:768px){
.navbar-nav{
background-color:gainsboro;
border:blue 2px solid;
float:left; /* left side */
}
.navbar-nav .nav-item{
border:blue 2px solid;
padding: 0px 10px;
}
}
Try this:
#media screen and (max-width:768px){
.navbar-nav{
background-color:gainsboro;
border:blue 2px solid;
}
.navbar-nav .nav-item{
border:blue 2px solid;
}
}

Not able to get rid of Navbar item top/bottom margin?

I'm new with Bootstrap 4 and SASS. I've been struggling to learn how to make changes but have been able get a couple done. However, one of them I can't seem to figure out is the margin or padding at the top and bottom of the navbar item.
Here is what I've done. On a new MVC project I installed Bootstrap 4 and Bootstrap.sass. I then created a new _custom-variables and copied the _variables content into it so that I can make some changes. I then created a _my-theme.scss file and imported all of them into my site.scss like this.
#import "scss/_custom-variables.scss";
#import "scss/_bootstrap.scss";
#import "scss/_my-theme.scss";
I was finally able to figure out how to change the background color of the navbar by creating a variable for my color and applying it to the _custom-variables and changing the link text to white:
$main-color: #0078D2;
// Navbar links
$navbar-default-link-color: #fff !default;
$navbar-default-link-hover-color: #fff !default;
$navbar-default-link-hover-bg: darken($main-color, 6.5%) !default;
I also had to set the following in the _my-theme.css to actually change the text color to white. I've watched some videos and I know it has to do with specifcicity but I still haven't really got my head wrapped around it. Based on a video I watched, what I did was inspect the link and found the properties that I just copied straight in to the _my-theme.scss.
This is what I had to add to the _my-theme.scss to get the text white.
.navbar-dark
.navbar-nav
.nav-link {
color: #fff;
margin-top: 0px;
margin-bottom: 0px;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus{
color: #fff;
}
However, there is still some padding or margin at the top each link that I would like to get rid of. You can see that I tried setting the margin-top: 0px and margin-bottom: 0px but that didn't work, neither did setting padding to 0px.
I also tried finding the setting in dev tools in Chrome but couldn't find what it is that is setting this.
This is my navbar layout:
<header>
<nav class="navbar navbar-default navbar-expand-md navbar-dark fixed-top rounded-0">
<a class="navbar-brand" href="#">Fixed navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<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>
</header>
How can I remove this spacing and make the dark blue take the whole height of the navbar?
By default the navbar class contains internal padding. If you want to remove the top and bottom padding, just add this CSS:
.navbar {
padding-top: 0;
padding-bottom: 0;
}
The space is padding, and not margins. Use the py-0 utility class to remove the padding from the navbar. And then add padding back to the nav-link to maintain the original height:
https://www.codeply.com/go/roU5MIf724
.navbar-dark
.navbar-nav
.nav-link {
color: #fff;
padding: 10px 0;
}
<nav class="navbar navbar-default navbar-expand-md navbar-dark fixed-top rounded-0 py-0">
<a class="navbar-brand" href="#">Fixed navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<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>

Resources