Challenge - 5 Problems
Dismissible Alert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate2:00remaining
What is the visual output of this Bootstrap dismissible alert?
Look at the following HTML code using Bootstrap 5. What will you see in the browser?
Bootsrap
<div class="alert alert-warning alert-dismissible fade show" role="alert"> <strong>Warning!</strong> This is a dismissible alert. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div>
Attempts:
2 left
💡 Hint
Remember that 'alert-warning' gives a yellow background and 'btn-close' creates a functional close button.
✗ Incorrect
The 'alert-warning' class styles the alert with a yellow background. The 'alert-dismissible' and 'btn-close' together create a close button that hides the alert when clicked. The 'fade show' classes add a smooth fade effect.
📝 Syntax
intermediate2:00remaining
Which option correctly adds a dismissible alert with a close button in Bootstrap 5?
Choose the correct HTML snippet that creates a dismissible alert with a close button that works.
Attempts:
2 left
💡 Hint
Bootstrap 5 uses 'btn-close' and 'data-bs-dismiss' attributes for dismissible alerts.
✗ Incorrect
Option A uses the correct class 'btn-close' and the correct attribute 'data-bs-dismiss="alert"' which Bootstrap 5 requires for the close button to work. Other options use outdated or incorrect classes or attributes.
❓ accessibility
advanced2:00remaining
Which attribute improves accessibility for the dismiss button in a Bootstrap alert?
What attribute should be added to the close button to help screen readers understand its purpose?
Attempts:
2 left
💡 Hint
Think about what label a screen reader needs to announce the button's function.
✗ Incorrect
The 'aria-label="Close"' attribute tells screen readers that the button is for closing the alert. 'role="button"' is redundant because the element is already a button. 'tabindex="-1"' removes the button from keyboard navigation, which is bad. 'aria-hidden="true"' hides the button from screen readers, which is also bad.
❓ selector
advanced2:00remaining
Which CSS selector targets only the close button inside a Bootstrap dismissible alert?
Choose the CSS selector that selects the close button inside alerts with class 'alert-dismissible'.
Attempts:
2 left
💡 Hint
Remember the difference between direct child (>) and any descendant (space).
✗ Incorrect
Option A selects any element with class 'btn-close' inside any descendant of '.alert-dismissible', which matches the close button inside the alert. Option A only selects direct children, which may fail if the button is nested. Options C and D look for elements with both classes on the same element, which is not the case.
🧠 Conceptual
expert2:00remaining
What happens if you omit the 'data-bs-dismiss="alert"' attribute on the close button in a Bootstrap dismissible alert?
Consider a dismissible alert with a close button that lacks the 'data-bs-dismiss="alert"' attribute. What is the result when the button is clicked?
Attempts:
2 left
💡 Hint
Bootstrap's JavaScript uses specific attributes to know which elements trigger actions.
✗ Incorrect
Bootstrap's JavaScript requires the 'data-bs-dismiss="alert"' attribute on the button to know it should hide the alert. Without it, clicking the button does nothing even if it looks like a close button.