Alert

Other topics

Alert Types

Unlike some other Bootstrap components like Buttons, the Alerts do not come with a default or primary styling, because they are meant to alert the user in a specific way.

<div class="alert alert-success" role="alert">
    Some action was completed successfully
</div>
<div class="alert alert-info" role="alert">
    Here is some information. Just FYI.
</div>
<div class="alert alert-warning" role="alert">
    Careful! You're about to do something dangerous.
</div>
<div class="alert alert-danger" role="alert">
    An error (or something dangerous) happened!
</div>

Alert basic example

<div class="container">
  <h2>Alerts</h2>
  <div class="alert alert-success">
    <strong>Success!</strong>
  </div>
  <div class="alert alert-info">
    <strong>Info!</strong>
  </div>
  <div class="alert alert-warning">
    <strong>Warning!</strong> All foelds are required
  </div>
  <div class="alert alert-danger">
    The username is required and can't be empty
  </div>
</div>

enter image description here

Animated Alerts

The .fade and .in classes adds a fading effect when closing the alert message.

<div class="alert alert-success fade in">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    <strong>Success!</strong> This is a good example!
</div>

Dismissible Alerts

To give an alert close functionality, all we need is to add data-dismiss="alert" to our close button.

<div class="alert alert-info alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    Sphinx of black quartz, judge my vow
</div>

enter image description here

.alert-dismissible and .close classes are optional, only useful for styling.

Link color in Alerts

To quickly provide a matching color for links inside any alert, we can use the .alert-link utility class.

<div class="alert alert-success">
    You have won! Click <a href="#" class="alert-link">here</a> to claim your prize ...
</div>

<div class="alert alert-info">
    You might want to check <a href="#"  class="alert-link">this</a> instead.
</div>

<div class="alert alert-warning">
    You are running out of coins. Buy more <a href="#" class="alert-link">here</a>.
</div>

<div class="alert alert-danger">
    Something went wrong. You can try <a href="#" class="alert-link">again</a> or ...
</div>

enter image description here

Contributors

Topic Id: 6434

Example Ids: 21283,22114,22115,22954,23091

This site is not affiliated with any of the contributors.