Bootstrap Alerts

Alerts provide contextual feedback messages for typical user actions. For proper styling, use one of the required contextual classes. Alerts can also contain additional HTML elements like headings, paragraphs and dividers.

images/coding/coding05.webp

For example,

<div class="alert alert-primary" role="alert">
A simple primary alert!
</div>

1. Link Color

Use the .alert-link utility class to quickly provide matching colored links within any alert. For example,

<div class="alert alert-success" role="alert">
A simple success alert with <a href="#" class="alert-link">an example link</a>.
</div>

2. Dismissing Alerts

You need to add a dismiss button and the .alert-dismissible class, which adds extra padding to the right of the alert and positions the .close button. On the dismiss button, add the data-dismiss="alert" attribute, which triggers the JavaScript functionality. Be sure to use the <button> element with it for proper behavior across all devices.

To animate alerts when dismissing them, you can add the .fade and .show classes.

For example,

<div class="alert alert-warning alert-dismissible fade show" role="alert">
This is a dismissible alert.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>

Bootstrap CSS

1. Basic Alert

.alert {
position: relative;
padding: .75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: .25rem;
}

2. Primary Alert

.alert-primary {
color: #004085;
background-color: #cce5ff;
border-color: #b8daff;
}

3. Alert Link

.alert-primary .alert-link {
color: #002752;
}
.alert-link {
font-weight: 700;
}