0
0
Bootsrapmarkup~20 mins

Offcanvas component in Bootsrap - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Offcanvas Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What is the visual output of this Offcanvas component code?

Look at this Bootstrap Offcanvas HTML snippet. What will you see when you click the button?

Bootsrap
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#demoOffcanvas" aria-controls="demoOffcanvas">Open Menu</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="demoOffcanvas" aria-labelledby="demoOffcanvasLabel">
  <div class="offcanvas-header">
    <h5 id="demoOffcanvasLabel">Menu</h5>
    <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  </div>
  <div class="offcanvas-body">
    <p>Welcome to the sidebar menu!</p>
  </div>
</div>
AA dropdown menu appears below the button with the text 'Welcome to the sidebar menu!'
BA modal popup appears in the center with the text 'Welcome to the sidebar menu!'
CNothing happens because the button lacks a JavaScript event listener.
DA sidebar slides in from the left with a header 'Menu' and a close button, showing the text 'Welcome to the sidebar menu!'
Attempts:
2 left
💡 Hint

Think about what offcanvas-start means in Bootstrap.

selector
intermediate
1:30remaining
Which CSS selector targets the close button inside the Offcanvas component?

Given the Offcanvas HTML below, which CSS selector correctly selects the close button?

<div class="offcanvas" id="myOffcanvas">
  <div class="offcanvas-header">
    <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  </div>
</div>
Abutton.btn-close[data-bs-dismiss="offcanvas"]
B#myOffcanvas .btn-close
C.offcanvas .btn-close[data-bs-dismiss="modal"]
D.offcanvas-header > button[data-bs-toggle]
Attempts:
2 left
💡 Hint

Look for the attribute that tells the button to close the offcanvas.

🧠 Conceptual
advanced
1:30remaining
What ARIA attribute ensures the Offcanvas component is accessible to screen readers?

Which ARIA attribute is essential to link the Offcanvas container with its label for accessibility?

Aaria-expanded
Baria-labelledby
Caria-hidden
Daria-controls
Attempts:
2 left
💡 Hint

Think about how screen readers know the title of the offcanvas.

layout
advanced
1:30remaining
How to make the Offcanvas appear from the bottom instead of the left?

Given this Offcanvas code, which class change makes it slide up from the bottom?

Bootsrap
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
  <!-- content -->
</div>
AChange <code>offcanvas-start</code> to <code>offcanvas-bottom</code>
BAdd <code>offcanvas-top</code> class alongside <code>offcanvas-start</code>
CReplace <code>offcanvas-start</code> with <code>offcanvas-end</code>
DAdd <code>offcanvas-right</code> class
Attempts:
2 left
💡 Hint

Bootstrap uses directional classes like offcanvas-start and offcanvas-bottom.

📝 Syntax
expert
2:00remaining
What error occurs if you omit the tabindex="-1" attribute on the Offcanvas container?

Consider this Offcanvas snippet missing tabindex="-1". What happens when you try to open it?

Bootsrap
<div class="offcanvas offcanvas-start" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
  <!-- content -->
</div>
AThe offcanvas opens but the close button does not work.
BThe offcanvas fails to open and throws a JavaScript error.
CThe offcanvas opens but keyboard focus is not trapped inside, causing accessibility issues.
DThe offcanvas opens but the screen reader cannot detect it.
Attempts:
2 left
💡 Hint

Think about keyboard navigation and focus management.