toasts.mdx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ---
  2. title: Toasts
  3. summary: Toasts are lightweight alert boxes which display for a few seconds after a user has taken an action, to inform them of the state or outcome. They can be used when a user clicks a button or submits a form and their aim is to provide feedback, rather than encourage to take action.
  4. bootstrapLink: components/toasts/
  5. description: Display lightweight alert notifications.
  6. ---
  7. ## Default markup
  8. Use the default toast message to inform users of the outcome of their action and provide additional information. It contains an `x` close button to make it possible for users to close the toast if they wish.
  9. ```html example code
  10. <div
  11. class="toast show"
  12. role="alert"
  13. aria-live="assertive"
  14. aria-atomic="true"
  15. data-bs-autohide="false"
  16. data-bs-toggle="toast"
  17. >
  18. <div class="toast-header">
  19. <span
  20. class="avatar avatar-xs me-2"
  21. style="background-image: url(/samples/avatars/018f.jpg)"
  22. ></span>
  23. <strong class="me-auto">Mallory Hulme</strong>
  24. <small>11 mins ago</small>
  25. <button
  26. type="button"
  27. class="ms-2 btn-close"
  28. data-bs-dismiss="toast"
  29. aria-label="Close"
  30. ></button>
  31. </div>
  32. <div class="toast-body">Hello, world! This is a toast message.</div>
  33. </div>
  34. ```
  35. ## Translucent
  36. Toasts blend over the elements they appear over. If a browser supports the `backdrop-filter` CSS property, the elements under a toast will be blurred.
  37. ```html example code
  38. <div
  39. class="toast show"
  40. role="alert"
  41. aria-live="assertive"
  42. aria-atomic="true"
  43. data-bs-autohide="false"
  44. data-bs-toggle="toast"
  45. >
  46. <div class="toast-header">
  47. <span
  48. class="avatar avatar-xs me-2"
  49. style="background-image: url(/samples/avatars/029m.jpg)"
  50. ></span>
  51. <strong class="me-auto">Mallory Hulme</strong>
  52. <small>11 mins ago</small>
  53. <button
  54. type="button"
  55. class="ms-2 btn-close"
  56. data-bs-dismiss="toast"
  57. aria-label="Close"
  58. ></button>
  59. </div>
  60. <div class="toast-body">Hello, world! This is a toast message.</div>
  61. </div>
  62. ```
  63. ## Stacking toasts
  64. Stack multiple toasts together by putting them within one `.toast-container`.
  65. ```html example height="260px"
  66. <div class="toast-container">
  67. <div
  68. class="toast show"
  69. role="alert"
  70. aria-live="assertive"
  71. aria-atomic="true"
  72. data-bs-autohide="false"
  73. data-bs-toggle="toast"
  74. >
  75. <div class="toast-header">
  76. <span
  77. class="avatar avatar-xs me-2"
  78. style="background-image: url(/samples/avatars/008m.jpg)"
  79. ></span>
  80. <strong class="me-auto">Dunn Slane</strong>
  81. <small>11 mins ago</small>
  82. <button
  83. type="button"
  84. class="ms-2 btn-close"
  85. data-bs-dismiss="toast"
  86. aria-label="Close"
  87. ></button>
  88. </div>
  89. <div class="toast-body">Hello, world! This is a toast message.</div>
  90. </div>
  91. <div
  92. class="toast show"
  93. role="alert"
  94. aria-live="assertive"
  95. aria-atomic="true"
  96. data-bs-autohide="false"
  97. data-bs-toggle="toast"
  98. >
  99. <div class="toast-header">
  100. <span
  101. class="avatar avatar-xs me-2"
  102. style="background-image: url(/samples/avatars/020m.jpg)"
  103. ></span>
  104. <strong class="me-auto">Mallory Hulme</strong>
  105. <small>7 mins ago</small>
  106. <button
  107. type="button"
  108. class="ms-2 btn-close"
  109. data-bs-dismiss="toast"
  110. aria-label="Close"
  111. ></button>
  112. </div>
  113. <div class="toast-body">This is another toast message.</div>
  114. </div>
  115. </div>
  116. ```