Alerts in Bootstrap
Thanks Successfully signed up . class='alert alert-success'
Login To post message you must login . class='alert alert-info'
Spam Don’t expose your email address. class='alert alert-warning'
Wrong Enter Correct email address. class='alert alert-danger'
Dismissible Alerts
×
Wrong Enter Correct email address. class='alert alert-danger'
Links inide AlertWe often add links inside the alert. Links will have its own style of font and colour which will be displayed inside the alert. Here is one example of a normal link inside an alert.
Thanks Successfully signed up .Login Now
By adding class='alert-link' to the link we can match the colour of the link to parent alert style.
Thanks Successfully signed up .Login Now
One more example.
Failed You must agree to our terms and conditions
Reading adding and removing classes from AlertWe often use the same alert box to communicate different type of messages. Based on the requirement ( or condition ) we can change the class associated with the alert box.Here d1 is the id of our alert message box. Reading the present associated class
Removing one class and adding another.
Removing present class and adding a new class.
Here is a DEMO script to apply all classes to one alert box by using different buttons.
Using your own class with alert.In the above demo we have used bootstrap available classes to change or update the style. You are not limited to use only above pre-defined classes. You can change the background colour and font to your favourite colour by adding style property. Keep this code inside your head tag to change colour of your alert.
Now add this class to your alert
Wants to try different colours ? Try this demo.
Managing the position and display of the alert boxHiding the alert box to show only when it is required.
While displaying the alert message if you want your alert box to push the content down then use position relative.
If you don’t want your alert box to push the content down then use position absolute.
With position absolute, your message will be shown at top even you have moved to bottom of your page ( invisible to user unless they move to top ) . If your page has more data and message should display at the top ( below the address bar or within viewing area) at a fixed position even if the page is scrolled down ( several pages moved ), then use position fixed.
You may like to show the message over the existing content ( above ) then use z-index .
Show the message at top right corner.
After showing the message hide the box after a time delay. ( JQuery part )
Here 4000 is the duration in milliseconds for which the alert box will be visible and after which it will FadeOut. Adjust this value as per your requirment.
Removing previous class and adding new classBased on the requirement we can apply different classes to our message box.
This article is written by plus2net.com team.
|
Most Popular JQuery Scripts | |
1 | Two dependant list boxes |
2 | Calendar with Date Selection |
3 | Data change by Slider |
4 | Show & Hide element |