📌 Objective: Learn how to create offcanvas navigation menus and sidebars for modern, responsive layouts in Bootstrap.
🔹 1. Introduction to Offcanvas Navigation & Sidebars
Offcanvas components create hidden sidebars that slide into view when triggered.
They are used for mobile-friendly menus, side navigation, or hidden content panels.
💡 Why Use Offcanvas & Sidebars?
✔️ Saves screen space – Hidden by default, slides in when needed.
✔️ Mobile-friendly – Ideal for small screens and app-style layouts.
✔️ Easy to implement – Bootstrap provides built-in support.
🔹 2. Basic Offcanvas Navigation
Offcanvas menus are hidden by default and appear when triggered.
✅ Example: Simple Offcanvas Navigation
🔹 What happens?
- The offcanvas menu slides in from the left when clicking the button.
- Clicking the close button (
btn-close
) hides the menu.
🔹 3. Offcanvas Sidebar with a Navbar
✅ Example: Navbar with an Offcanvas Sidebar
🔹 What happens?
- The sidebar appears when clicking the ☰ button.
- Each menu item is styled using Bootstrap’s
.list-group
.
🔹 4. Offcanvas Positioning & Variants
By default, offcanvas components slide in from the left (offcanvas-start
).
You can change its position using these classes:
Class | Effect |
---|---|
.offcanvas-start |
Left sidebar (default) |
.offcanvas-end |
Right sidebar |
.offcanvas-top |
Slides in from the top |
.offcanvas-bottom |
Slides in from the bottom |
✅ Example: Right-Side Offcanvas
🔹 What happens?
- The offcanvas slides in from the right instead of the left.
🔹 5. Full-Screen Offcanvas Menu
Use .offcanvas-full
to create a full-screen menu experience.
✅ Example: Full-Screen Offcanvas
🔹 What happens?
- The menu covers the entire screen from the top.
🔹 6. Permanent Sidebar for Desktop Layouts
Use .d-lg-block
to keep the sidebar always visible on large screens but collapsible on mobile.
✅ Example: Sidebar for Desktop & Offcanvas for Mobile
🔹 What happens?
- On large screens (
lg
), the sidebar is always visible. - On mobile (
d-lg-none
), it becomes an offcanvas menu.
📝 Lesson Recap Quiz
🎯 Test your knowledge of Bootstrap Offcanvas & Sidebars.
📌 Multiple-Choice Questions (MCQs)
1️⃣ What class is used to create a Bootstrap Offcanvas sidebar?
a) .sidebar-menu
b) .offcanvas
c) .nav-offcanvas
d) .menu-sidebar
✅ Correct Answer: b) .offcanvas
2️⃣ How can you make an offcanvas menu appear from the right side?
a) .offcanvas-right
b) .offcanvas-end
c) .offcanvas-left
d) .offcanvas-side
✅ Correct Answer: b) .offcanvas-end
📌 True or False
3️⃣ Offcanvas navigation works without Bootstrap’s JavaScript.
✅ Answer: False (It requires Bootstrap’s JavaScript.)
4️⃣ .d-lg-block
keeps a sidebar visible on large screens.
✅ Answer: True
🎯 Practical Challenge
✅ Create a sidebar that is always visible on desktops but offcanvas on mobile.
✅ Build a right-side offcanvas menu with links and a close button.
✅ Post your solution in the discussion forum for feedback!
🎓 Lesson Summary
✅ Offcanvas (.offcanvas
) creates hidden sidebars that slide in on button click.
✅ .offcanvas-start
, .offcanvas-end
, .offcanvas-top
, .offcanvas-bottom
control positioning.
✅ Permanent sidebars can be hidden on mobile and visible on desktop.
Leave a Reply