Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages. For inline dismissal, use the [alerts jQuery plugin]({{ site.baseurl }}javascript/#alerts).
Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
Wrap any text and an optional dismiss button in `.alert` and one of the four contextual classes (e.g., `.alert-success`) for basic alert messages.
## Examples
{% callout info %}
#### No default class
Alerts don't have default classes, only base and modifier classes. A default gray alert doesn't make too much sense, so you're required to specify a type via contextual class. Choose from success, info, warning, or danger.
Alerts are available for any length of text, as well as an optional dismiss button. For proper styling, use one of the four **required** contextual classes (e.g., `.alert-success`). For inline dismissal, use the [alerts jQuery plugin](#dismissing).
{% endcallout %}
{% example html %}
{% example html %}
<divclass="alert alert-success"role="alert">
<divclass="alert alert-success"role="alert">
...
@@ -28,26 +24,6 @@ Alerts don't have default classes, only base and modifier classes. A default gra
...
@@ -28,26 +24,6 @@ Alerts don't have default classes, only base and modifier classes. A default gra
</div>
</div>
{% endexample %}
{% endexample %}
### Dismissing
Build on any alert by adding an optional `.alert-dismissible` and [close button]().
<strong>Warning!</strong> Better check yourself, you're not looking too good.
</div>
{% endexample %}
{% callout warning %}
#### Ensure proper behavior across all devices
Be sure to use the `<button>` element with the `data-dismiss="alert"` data attribute.
{% endcallout %}
### Link color
### Link color
Use the `.alert-link` utility class to quickly provide matching colored links within any alert.
Use the `.alert-link` utility class to quickly provide matching colored links within any alert.
...
@@ -67,8 +43,16 @@ Use the `.alert-link` utility class to quickly provide matching colored links wi
...
@@ -67,8 +43,16 @@ Use the `.alert-link` utility class to quickly provide matching colored links wi
</div>
</div>
{% endexample %}
{% endexample %}
### Dismissing
## Examples
Using the alert JavaScript plugin, it's possible to dismiss any alert inline. Here's how:
- Be sure you've loaded the alert plugin, or the compiled Bootstrap JavaScript.
- 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, be sure to add the `.fade` and `.in` classes.
<h5class="alert-heading">Sorry, something went wrong.</h5>
<p>Change this and that and try again. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.</p>
<p>
<buttontype="button"class="btn btn-danger">Take this action</button>
<buttontype="button"class="btn btn-secondary">Or do this</button>
</p>
</div>
{% endexample %}
## Usage
### Triggers
Enable dismissal of an alert via JavaScript:
Enable dismissal of an alert via JavaScript:
...
@@ -102,9 +74,7 @@ Enable dismissal of an alert via JavaScript:
...
@@ -102,9 +74,7 @@ Enable dismissal of an alert via JavaScript:
$(".alert").alert()
$(".alert").alert()
{% endhighlight %}
{% endhighlight %}
### Markup
Or with `data` attributes on a button **within the alert**, as demonstrated above:
Just add `data-dismiss="alert"` to your close button to automatically give an alert close functionality. Closing an alert removes it from the DOM.