Bootstrap Tutorial - Bootstrap alert control








Alert control

Alert provides contextual feedback messages for typical user actions with the handful of available and flexible alert messages. For inline dismissal, use the alerts jQuery plugin.

Wrap any text and an optional dismiss button in .alert for a basic warning alert message.

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!--from   w  ww.  j  a v  a  2s .c  o  m-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin: 20px;'>

  <div class="alert">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong>Warning!</strong> Best check yo self, you're not looking too
    good.
  </div>
</body>
</html>

Click to view the demo





Example

The following code adds optional classes to change an alert's connotation. It uses danger class to mark an alert box.

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!--from  w  w w  .  j  av  a 2 s . c om-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin: 20px;'>

  <div class="alert alert-danger">
    <button type="button" class="close" data-dismiss="alert">?</button>
    <strong>Oh snap!</strong> Change a few things up and try submitting
    again.
  </div>
</body>
</html>

Click to view the demo





Success alert

Success alert

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!--  w  w  w  .java2s  .c  o m-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin: 20px;'>

  <div class="alert alert-success">
    <button type="button" class="close" data-dismiss="alert">?</button>
    <strong>Well done!</strong> You successfully read this important alert
    message.
  </div>
</body>
</html>

Click to view the demo

Information alert

Information alert.

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!--from  w w w .  j  a v a  2 s.c  o m-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin: 20px;'>

  <div class="alert alert-info">
    <button type="button" class="close" data-dismiss="alert">?</button>
    <strong>Heads up!</strong> This alert needs your attention, but it's
    not super important.
  </div>
</body>
</html>

Click to view the demo

alert-danger

We can use the .alert-link utility class to quickly provide matching colored links within any alert.

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!--   w  w w  .jav  a 2  s  .com-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin: 20px;'>

  <div class="alert alert-danger">
    <button type="button" class="close" data-dismiss="alert">?</button>
    <strong>Oh snap!</strong> <a href="#" class="alert-link">Change a
      few things up</a> and try submitting again.
  </div>
</body>
</html>

Click to view the demo