Alert Class
One of the ready-made css classes BootStrap offers for div and similar elements is the alert class.
Using the Alert class, we can easily apply ready-made views to elements such as divs, spans, etc., usually to give a message to the visitor.
Sample:
Warning! Check the information you entered.
In the example above, alert class has been applied to a div tag. The codes are as follows:
<div class="alert alert-danger">
<strong>Warning!</strong> Check the information please
.
</div>
The content inside the div element is up to you.
Two separate classes have been applied to the div tag, and the alert-danger selector has given a red-toned appearance. Other options are as follows:
alert-success selector:
Successful! Process completed.
alert-info selector:
Info! All the content is protected.
alert-warning selector:
Warning! Please read the terms.
You can review the codes in the topic examples section and try it yourself.
If we apply the alert-link selector to a link in the section with the alert class applied, that link will acquire a color that matches the element it is in:
<div class="alert alert-danger">
<strong>Warning!</strong> An error occured! <a class="alert-link" href="#">Click to go home page.</a>
</div>
Close Button
If we want the element to which the Alert class is applied to be closed by the visitor;
-
Implement the alert-dismissible class as well as the alert class.
-
For the close button create a link or button inside the tag and apply the class="close" and data-dismiss="alert" parameters.
Thus, the user clicks that link or button to create a div etc. can hide the element.
X Congratulations! Your application has been approved.
<div class="alert alert-success alert-dismissible">
<a aria-label="close" class="close" data-dismiss="alert" href="#">X</a>
<strong>Congrats!</strong> Your application has been approved.
</div>
If we apply the .fade and .in selectors as well, the fade effect will occur on shutdown.
<div class="alert alert-danger alert-dismissible fade in">
<a aria-label="close" class="close" data-dismiss="alert" href="#">Close</a>
<strong>Warning
!</strong> Review the information.
</div>
Close Warning! Review the information.
It is beneficial for us to use the aria-label parameter in terms of accessibility.
How to use bootstrap alert, use of alert class, what is bootstrap alert, how to use alert, bootstrap lessons alert topic, closeable div, closing div
EXERCISES
BootStrap Alert Class Examples
|
Try It
|
Read 870 times.