DEV Community

Cover image for Bootstrap 5 Sidebar Examples

Bootstrap 5 Sidebar Examples

Carol Skelly on April 12, 2021

Now that Bootstrap 5 has a Offcanvas component 👏, it makes sense to explore building a Bootstrap 5 Sidebar. Sidebars are often used for vertical na...
Collapse
 
pgarciabaez profile image
Patricio García

I have a problem in Sidebar Example 2 when I try to introduce a big responsive table in the text. As you can see in my fork of it (codeply.com/p/PNoCYKK8Wk), using table view there is an overlapping between the sidebar and the contents. Do you know how I can fix this problem?

Collapse
 
hayesb profile image
Brian C. Hayes • Edited

I know this is a bit old, but I think what you were saying is that the content area is not forcing the nav to collapse to the top of the screen when on mobile devices. If there is not enough content in the content area, the nav bar is expanding vertically.

To fix this, I looked at the other examples, and noticed that many of them are using this on the div tags around the content "min-vh-100". This is basically saying minimum vertical heigh of 100% where the content is displayed.

<class="col pt-4 min-vh-100">
CONTENT HERE
</div>

This should push the nav bar up so that it is compressed to the correct size.

Collapse
 
carolskelly profile image
Carol Skelly

I'm not seeing overlap.. I'm seeing the table wrap. Is that what you mean?

Collapse
 
pgarciabaez profile image
Patricio García

There is an overlap when I scroll, but finally I solved it adding "col-sm-9" in div class of line 62. Thanks

Collapse
 
afif profile image
Temani Afif

Ah, Zim is on DEV. Nice seeing you here 👍

Collapse
 
carolskelly profile image
Carol Skelly

Hello 👋 my SO friend, Nice see you too!

Collapse
 
afif profile image
Temani Afif

I want you to crash DEV 💥 with Boostrap posts!

PS: you can add html in front of the 3 slashes to have a colored code dev-to-uploads.s3.amazonaws.com/up...

Thread Thread
 
carolskelly profile image
Carol Skelly

Cool... much better 😉 thanks for the tip!

Collapse
 
glennvorhes profile image
glennvorhes

Great post that was exactly what I was looking for. Example 1 was what I wanted to do but there was one minor glitch that was bugging me. You can see it in the GIF and in the live demo as well - there's a small but noticeable delay when expanding items 2+ in the sub menus. The submenu ul elements have the nav class applied and with that comes flex-wrap: wrap. If you set this to the default nowrap in your own css that delay/glitch completely goes away just with the following applied after bootstrap's css

assuming the top level menu ul element id is 'menu'

        #menu li > ul.nav{
            flex-wrap: nowrap;
        }
Enter fullscreen mode Exit fullscreen mode

Thanks for the great post!

Collapse
 
franbejarano profile image
Fran Bejarano

Hello.

I am new coding with bootstrap and web developmente in general. I was wondering if there is a way to implement this sidebar in every page without the need to paste the code in all the pages.

Thanks!

Collapse
 
neutromancer profile image
neutromancer

Neat examples, I have a problem with Example 2 tho... in the "sticky footer" version, both the footer and the top navbar stretch to fill the space if there is not enough text to fill the page. This doesn't happen in the "normal footer" version. Is there any class or tag that can be added to prevent this?
This isn't normally noticeable in the Demo since there's a bunch of placeholder text, but if I delete some of it, it stretches.

Collapse
 
lexiebkm profile image
Alexander B.K. • Edited

Good article. But I am not really satisfied when seeing the result of Example 6, i.e "Push" Sidebar.
My only concern is on the placement of the element/component used for toggling the sidebar. When the sidebar is shown/open, I think the appearance of the toggle element on the main element is not intuitive, even a bit confusing. The sidebar is already open, why should we need to display the toggle element on the main element/section ? In that situation, it appears as if there will be another menu content when user click the toggle element.
We quite often see in real applications, the toggle element is usually placed on the sidebar itself when the sidebar is open, commonly using certain icon on the right side of the sidebar. Only when the sidebar is closed, then the toggle element (with text) is placed and appears on the main element/section.
I realize that in order to achieve that purpose, it needs additional work and might be tricky.

For comparison, we can see on bootsnipp.com/snippets/Q0dAX which uses version 4, but yeah... it requires additional work on CSS.

Collapse
 
viragdesai profile image
Virag Dilip Desai

Very nice! Great, simple and fantastic examples!

Collapse
 
ramkipvrs profile image
Ramakrishnan Srinivasan

Hi,
New to DEV community, I have opened the Sidebar Example 1 in Codeply, but I see only HTML 5 code,

is it that I should be coding the respective Java Script and CSS files, hope I am not missing something basic here to get them,

Can someone please guide me?

Thanks

Collapse
 
2pulses profile image
2pulses

Nicely done! One question: how does one place the horizontal Navbar in Example #2 to the bottom as opposed to the top? I've tried changing to "fixed-bottom" but then the Sidebar no longer occupies the full length of the screen.

Collapse
 
paulkd profile image
Paul Dunderdale

I haven't checked/tried your code, but there is absolutely nothing wrong with Bootstrap, or the Bootstrap Offcanvas component (which displays just fine on mobile).

Collapse
 
franpn84 profile image
Francesco

Hi everyone,
I really liked the examples and wanted to try Sidebar Example 6. I made a new React project and added bootstrap and react-bootstrap latest versions. Clicking the button does not close the menu. Do you happen to know how I could fix this?

Collapse
 
devmedtz profile image
DevMed

Its real amazing

Collapse
 
karenpayneoregon profile image
Karen Payne

Well written for getting started.

demo

Collapse
 
rumendimov profile image
Rumen Dimov

Amazing content! That's what I needed! Thank you

Collapse
 
faizbyp profile image
Faiz Byputra

Thanks! Looking for this but on the Bootstrap 5 documentation there's only an offcanvas

Collapse
 
foussenitoure profile image
foussenitoure

thank DEV community i am just used your templates sidebar

Collapse
 
davidvandertuijn profile image
David van der Tuijn

Looking for examples with font awesome icons

Collapse
 
udo_schmitz_184a9d42ff3bd profile image
Udo Schmitz

Super interesting. Unfortunately I can’t see any of the examples. Codeply certificate expired?

Collapse
 
udo_schmitz_184a9d42ff3bd profile image
Udo Schmitz

Working again :)

Collapse
 
azure_ profile image
John Oh

Just a quick question but am I allowed to take this work and implement it into my website? I might change some style here and there but take the general template you have built.

Collapse
 
azure_ profile image
John Oh

I don't wanna be getting into any legal troubles because I'm pretty new to publishing a website online...

Collapse
 
ramone04 profile image
Ramone04

Hello, can you please tell me what is the stylesheet link?

Collapse
 
bjoyval profile image
bjoyval

i just wanna ask, how i can change the bg color of menu bar from the example 1, as you can see from my qst, im a newbie, sorry

Collapse
 
samyhosni profile image
Sami El Hosni

Hello community, i'm new on bootstrap and i have a question may it can be crazy :
why when i use the code i can't see the colors , it appears all white !
Thank you