Complete the code to create a button that toggles the offcanvas component.
<button class="btn btn-primary" type="button" data-bs-toggle="[1]" data-bs-target="#offcanvasExample" aria-controls="offcanvasExample"> Toggle Offcanvas </button>
The attribute data-bs-toggle="offcanvas" tells Bootstrap that this button will toggle an offcanvas component.
Complete the code to set the offcanvas component to appear from the right side.
<div class="offcanvas [1]" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel"> <div class="offcanvas-header"> <h5 class="offcanvas-title" id="offcanvasExampleLabel">Offcanvas Right</h5> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button> </div> <div class="offcanvas-body"> Content goes here. </div> </div>
The class offcanvas-end makes the offcanvas appear from the right side.
Fix the error in the offcanvas close button to properly dismiss the offcanvas.
<button type="button" class="btn-close" data-bs-dismiss="[1]" aria-label="Close"></button>
The attribute data-bs-dismiss="offcanvas" tells Bootstrap to close the offcanvas when this button is clicked.
Fill both blanks to create an offcanvas that is scrollable and has a backdrop.
<div class="offcanvas [1]" data-bs-scroll="[2]" tabindex="-1" id="offcanvasScrollable" aria-labelledby="offcanvasScrollableLabel"> <div class="offcanvas-header"> <h5 class="offcanvas-title" id="offcanvasScrollableLabel">Scrollable Offcanvas</h5> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button> </div> <div class="offcanvas-body"> Lots of content here... </div> </div>
The class offcanvas-start sets the offcanvas to slide in from the left. The attribute data-bs-scroll="true" allows the offcanvas body to be scrollable.
Fill all three blanks to create an offcanvas with a header title, a body paragraph, and a close button with proper ARIA label.
<div class="offcanvas offcanvas-[1]" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel"> <div class="offcanvas-header"> <h5 class="offcanvas-title" id="offcanvasExampleLabel">[2]</h5> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="[3]"></button> </div> <div class="offcanvas-body"> <p>This is the offcanvas body content.</p> </div> </div>
The class offcanvas-end makes the offcanvas slide in from the right. The header title is set to 'Offcanvas Title'. The close button has an ARIA label 'Close' for accessibility.