offcanvas.mdx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ---
  2. title: Offcanvas
  3. ---
  4. Offcanvas is a sidebar component that can be toggled via JavaScript to appear from the left, right, top, or bottom edge of the viewport. Buttons or anchors are used as triggers that are attached to specific elements you toggle, and `data` attributes are used to invoke our JavaScript.
  5. ## Basic usage
  6. To create an offcanvas, add the `.offcanvas` class to a container element. You can also add the `.offcanvas-start`, `.offcanvas-end`, `.offcanvas-top`, or `.offcanvas-bottom` class to specify the position of the offcanvas. The `.show` class is used to display the offcanvas.
  7. ```html
  8. <div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvas">
  9. <div class="offcanvas-body">
  10. Content for the offcanvas goes here. You can place just about any Tabler component or custom
  11. elements here.
  12. </div>
  13. </div>
  14. ```
  15. Look at the example below to see how the offcanvas works.
  16. ```html example vendors height="25rem"
  17. <div
  18. class="offcanvas offcanvas-start show"
  19. tabindex="-1"
  20. id="offcanvas"
  21. aria-labelledby="offcanvasLabel"
  22. >
  23. <div class="offcanvas-body">
  24. Content for the offcanvas goes here. You can place just about any Tabler component or custom
  25. elements here.
  26. </div>
  27. </div>
  28. ```
  29. ## Cookies banner
  30. The offcanvas component is used to display a cookies banner. It is a great way to inform users about the use of cookies on your website and to get their consent.
  31. ```html example vendors height="25rem"
  32. <div
  33. class="offcanvas offcanvas-bottom h-auto show"
  34. tabindex="-1"
  35. id="offcanvasBottom"
  36. aria-modal="true"
  37. role="dialog"
  38. >
  39. <div class="offcanvas-body">
  40. <div class="container">
  41. <div class="row align-items-center">
  42. <div class="col">
  43. <strong>Do you like cookies?</strong> πŸͺ We use cookies to ensure you get the best
  44. experience on our website.
  45. <a href="./terms-of-service.html" target="_blank">Learn more</a>
  46. </div>
  47. <div class="col-auto">
  48. <button type="button" class="btn btn-primary" data-bs-dismiss="offcanvas">
  49. Essential Cookies Only
  50. </button>
  51. </div>
  52. <div class="col-auto">
  53. <button type="button" class="btn btn-primary" data-bs-dismiss="offcanvas">
  54. Allow All Cookies
  55. </button>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. ```