Usage
All alerts are prefixed with the alert
class. This gives the element some common
properties for the alert, such as margin and padding. There are three different types of alerts to choose from, take a look at below.
All alerts are prefixed with the alert
class. This gives the element some common
properties for the alert, such as margin and padding. There are three different types of alerts to choose from, take a look at below.
Plain alerts feature a border on the left & content. The text color is dynamically made and slightly darker than the alert itself.
You just need to label your container with the alert
class and add your color by specifiying alert-{color}
.
<div class="alert">
This is a default alert
</div>
<div class="alert alert-primary">
This is a primary alert
</div>
<div class="alert alert-success">
This is a success alert
</div>
<div class="alert alert-info">
This is an info alert
</div>
<div class="alert alert-warning">
This is a warning alert
</div>
<div class="alert alert-danger">
This is a danger alert
</div>
<div class="alert alert-link">
This is a link alert
</div>
To acheive a colored background, attach the alert-background
class alongside alert-{color}
to select the color.
<div class="alert alert-primary alert-background">
This is a primary alert
</div>
<div class="alert alert-success alert-background">
This is a success alert
</div>
<div class="alert alert-info alert-background">
This is an info alert
</div>
<div class="alert alert-warning alert-background">
This is a warning alert
</div>
<div class="alert alert-danger alert-background">
This is a danger alert
</div>
<div class="alert alert-link alert-background">
This is a link alert
</div>
Alerts can have a close button placed on the right of the alert
. The close element
should be a button
and be prefixed with close
.
The alert-close
class must be placed on the alert you intend to have the close
button in. This will give padding to the right of the content.
Note: To make an alert dismissable, please see the bottom of this page.
<div class="alert alert-success alert-close">
This is a success alert with close button
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-info alert-close">
This is an info alert with close button
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-warning alert-close">
This is a warning alert with close button
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="alert alert-danger alert-close">
This is a danger alert with close button
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
Adding any icons to alerts is easy, you can do it natively with slight margin added to separate the content. See below for an example"
<div class="alert alert-danger alert-close alert-background">
<i class="far fa-angry mr-2"></i>
<strong>Danger alert:</strong>
We're sorry, but all the cake has gone.
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
You can design matereialstic looking cards without any need of any additional classes easy as that, take a look at the notation below and copy if you like the look of it!
Note: You are not limited to the primary color, you can use any in your palette.
<div class="alert alert-white alert-close alert-background py-0 pl-0 d-flex align-items-center">
<div class="bg-primary p-4 mr-3">
<i class="fas fa-shopping-cart c-white"></i>
</div>
<div class="d-flex flex-column justify-content-center">
<strong>Added to cart</strong>
<span>The item was added to the shopping cart.</span>
</div>
<button type="button" class="close mx-4 p-0" aria-label="Close">
<span class="c-primary" aria-hidden="true">×</span>
</button>
</div>
You can use pure CSS to dismiss an alert, the markup is slightly different but it's easy to implement and your build becomes lighter.
alert-container
element must be the parent for both the alert and the
checkbox.checkbox
should be placed before the alert in the DOMcheckbox
and the name of the label must match.Go ahead and click the close button to dismiss the alerts.
<div class="alert-container">
<input type="checkbox" class="alert-toggle" id="alertdismiss1">
<div class="alert alert-success alert-background alert-close">
This is a success alert with close button functionality
<label for="alertdismiss1" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</label>
</div>
</div>
mesh doesnt ship with any JS, but you can use the following function to dismiss the alerts. This script adds an
event listener to all the close
buttons.
document.addEventListener('DOMContentLoaded', () => {
(document.querySelectorAll('.alert .close') || []).forEach((close) => {
close.addEventListener('click', () => {
close.parentNode.remove();
});
});
});
Go ahead and click the close button to dismiss the alerts.
Customise the alert style via border-radius and choose what close method you prefer.
Variable | Value | Description |
---|---|---|
|
Boolean | Enables/disables the full coloured background styled alert. |
|
Boolean | Enables/disables the shadow effect for full coloured background styled alert. |
|
Boolean | Enables/disables the pure CSS close functionality. |
|
Boolean | Enables/disables the JS close functionality. |
|
Color | Box shadow color for alerts. |