Look at this Bootstrap Offcanvas HTML snippet. What will you see when you click the button?
<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>
Think about what offcanvas-start means in Bootstrap.
The offcanvas-start class makes the sidebar slide in from the left side. The button toggles this sidebar. The content inside the offcanvas is shown inside the sliding panel.
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>Look for the attribute that tells the button to close the offcanvas.
The close button has data-bs-dismiss="offcanvas". The selector button.btn-close[data-bs-dismiss="offcanvas"] matches it exactly.
Which ARIA attribute is essential to link the Offcanvas container with its label for accessibility?
Think about how screen readers know the title of the offcanvas.
The aria-labelledby attribute points to the element that labels the offcanvas, usually the header. This helps screen readers announce the offcanvas title.
Given this Offcanvas code, which class change makes it slide up from the bottom?
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel"> <!-- content --> </div>
Bootstrap uses directional classes like offcanvas-start and offcanvas-bottom.
The class offcanvas-bottom makes the offcanvas slide up from the bottom edge of the screen.
tabindex="-1" attribute on the Offcanvas container?Consider this Offcanvas snippet missing tabindex="-1". What happens when you try to open it?
<div class="offcanvas offcanvas-start" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel"> <!-- content --> </div>
Think about keyboard navigation and focus management.
The tabindex="-1" attribute allows the offcanvas container to receive focus programmatically. Without it, keyboard users cannot navigate properly inside the offcanvas, causing accessibility problems.