bootstrap 5 accordion not working,Bootstrap 5 Sidebar Examples

Now that Bootstrap 5 has a Offcanvas component 👏, it makes sense to explore building a Bootstrap 5 Sidebar. Sidebars are often used for vertical navigation, but they can really be used for any content that's an aside to main content.

Sidebars can get complex. There are many things to consider...

Responsive? different width, visibility or orientation based on screen width?

Multi-level? do the nav items have sub levels? Will this impact height, scrolling or visibility of items?

Toggleable? can the sidebar be toggled by a button or "hamburger"?

Push vs. Overlay? is main content hidden behind or next to the sidebar?

Left or Right? is the sidebar to the left or right of main content?

Fixed or Sticky? how is the sidebar positioned on page scroll?

Animation Style? slide left/right/up/down?, collapse?

IMO, the best way to get after all of the above considerations is to look at various Sidebar examples. These examples demonstrate Sidebars with navigation since that's what I consider to be the primary function. The examples also use common page layouts and content, because Sidebars are often impacted by the entire page layout.

Sidebar Example 1

Left vertical sidebar with submenus

Here's a left side 2-level vertical sidebar with collapsible menu items. The menu functions like an "accordion" where only a single menu is open at a time. It's also responsive which allows the main content area to be visible. The sidebar shrinks in width, hides the text labels and collapses to icons only on mobile devices.

Alt Text

HTML Markup

Menu Home Dashboard Item 1 Item 2 Orders Bootstrap Item 1 Item 2 Products Product 1 Product 2 Product 3 Product 4 Customers loserNew project...SettingsProfileSign outContent area...Enter fullscreen modeExit fullscreen mode

Example 1 - Demo

Sidebar Example 2

Vertical sidebar that changes to navbar on mobile

This 2nd example is a vertical sidebar (on large screens) that switches to a horizontal navbar (on smaller mobile screens). It's a multi-level sidebar with collapsible menu items. The menu functions like an "accordion" where only a single menu is open at a time.

This sidebar layout also considers sticky and scrolling behaviors. The sidebar and bottom footer both appear fixed on larger screens. Only the content area is scrollable (when content height allows). On mobile screens, the horizontal sidebar remains fixed at the top (using sticky position), and the remaining content and footer sections scroll the entire page height. For this reason a small CSS change is need to make the height responsive...

Alt Text

HTML Markup

New project...SettingsProfileEnter fullscreen modeExit fullscreen mode

Example 2 - Demo

If you don't need the sticky footer, here's a slight variation that doesn't reguire extra CSS

Sidebar Example 3

Sidebar with Bootstrap icons

The next example is similar to the prior as it changes to horizontal orientation on mobile. This full height example has big beautiful icons from Bootstrap icons. This example also use sticky position to make the sidebar appear fixed as the page is scrolled.

Alt Text

HTML Markup

New project...SettingsProfileEnter fullscreen modeExit fullscreen mode

Example 3 - Demo

Sidebar Example 4

Collapse off-canvas left sidebar

This is the first collapsible example, and it's done using Bootstrap 5's new Offcanvas component. This left sidebar overlays the main content area and can be hidden/shown using a toggle button.

Alt Text

HTML Markup

MenuHomeDashboard OrdersBootstrapNew project...SettingsProfileSign outProductsCustomers Content..Enter fullscreen modeExit fullscreen mode

Example 4 - Offcanvas "overlay" Sidebar Demo

Sidebar Example 5

Navbar with search form and left sticky sidebar

This last example considers other components like the top Navbar and main content area. The sidebar uses sticky-top to appear fixed on the left side so that it remains in place as the page is scrolled. On mobile, the sidebar switches to a horizontal icon bar positioned below the Navbar.

Example 5 - Navbar + Sidebar Demo

Sidebar Example 6

Simple offcanvas "push" sidebar

If you read my Bootstrap 5 Offcanvas article you've seen that the Offcanvas component is for an "overlay" type sidebar. However, if you want a "push" type sidebar, the Offcanvas component isn't going to work.

To create a "push" type sidebar, instead use a Bootstrap grid column to contain the sidebar, and the Collapse component to toggle it open/closed...

Item (more nav items) ... MenuContent area...Enter fullscreen modeExit fullscreen mode

Example 6 - Simple "push" Sidebar Demo

Did you notice that all of the above examples were done using only Bootstrap classes? 😎 This means you don't need custom CSS to create a Sidebar with Bootstrap 5.

It's also worth taking a look 👀 at Bootstrap's official sidebar examples. The official Bootstrap examples don't consider entire page layout, but still may be helpful when considering the sidebar content alone. Discover what else is new in Bootstrap 5

I hope these Sidebar example will kickstart your next Bootstrap project. Let me know your thoughts in the comments!

bootstrap 5 nested accordionbootstrap accordion not collapsingbootstrap accordion expand allbootstrap accordion collapsebootstrap accordion menubootstrap accordion codepenaccordion button bootstrapbootstrap accordion blazorbootstrap5 教程bootstrap5.0bootstrap5中文文档bootstrap v5Bootstrap 4bootstrap5 正式版bootstrap 5 jqueryBootstrap 5.0.0bootstrap4.6bootstrap v4搜索不到ip地址怎么办幼儿教育心理学心得体会10000字秋天的第一杯奶茶是弄啥的苏州罗技电子厂35一小时靠谱吗西瓜视频信用分在哪里查看爱国美女教授庆余年2开机了吗旅游管理要学什么课程明年的工作目标标题2021年50岁是哪年出生的万物理论男主