Bootstrap 提示



Bootstrap 提示

Bootstrap Alerts

Bootstrap Alerts用于提供创建预定义提示消息的简便方法。 Alert为您的消息添加了一种样式,以使其对用户更具吸引力。
在<div>元素内使用四个类来发出警报。

.alert-success
.alert-info
.alert-warning
.alert-danger

启动警报示例

    <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Alerts</h2>
  <div class="alert alert-success">
    <strong>Success!</strong> this alert box indicates a successful or positive action.
  </div>
  <div class="alert alert-info">
    <strong>Info!</strong> this alert box indicates a neutral informative change or action.
  </div>
  <div class="alert alert-warning">
    <strong>Warning!</strong> this alert box indicates a warning that might need attention.
  </div>
  <div class="alert alert-danger">
    <strong>Danger!</strong> this alert box indicates a dangerous or potentially negative action.
</div>
</div>
</body>
</html>


Bootstrap4 Alerts

Bootstrap 4在Bootstrap 3教程中定义的Bootstrap Alert中添加了4个新Alerts。
这些是:

Primary: 该警报框表示重要的操作。
Secondary: 此警报框指示次要操作。
Dark: 深灰色警报框。
Light: 浅灰色警报框。

使用.alert类创建警报,然后创建其中一个上下文类。
所有上下文类的列表:

.alert-success
.alert-info
.alert-warning
.alert-danger
.alert-primary
.alert-secondary
.alert-light
.alert-dark

示例

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Alerts</h2>
  <div class="alert alert-success">
    <strong>Success!</strong> Used to indicate successful or positive action.
  </div>
  <div class="alert alert-info">
    <strong>Info!</strong> Used to indicate a neutral informative change or action.
  </div>
  <div class="alert alert-warning">
    <strong>Warning!</strong> Used to indicate a warning that might need attention.
  </div>
  <div class="alert alert-danger">
    <strong>Danger!</strong> Used to indicate a dangerous or potentially negative action.
  </div>
  <div class="alert alert-primary">
    <strong>Primary!</strong> Used to indicate an important action.
  </div>
  <div class="alert alert-secondary">
    <strong>Secondary!</strong> Used to indicate a slightly less important action.
  </div>
  <div class="alert alert-dark">
    <strong>Dark!</strong> Dark grey alert.
  </div>
  <div class="alert alert-light">
    <strong>Light!</strong> Light grey alert.
  </div>
</div>
</body>
</html>


Alerts链接

您必须将警报链接类添加到警报框内的任何链接,以创建"匹配的彩色链接":

示例:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Bootstrap Alert Links</h2>
  <div class="alert alert-success">
    <strong>Success!</strong> You should <a href="#" class="alert-link">read this message</a>.
  </div>
  <div class="alert alert-info">
    <strong>Info!</strong> You should <a href="#" class="alert-link">read this message</a>.
  </div>
  <div class="alert alert-warning">
    <strong>Warning!</strong> You should <a href="#" class="alert-link">read this message</a>.
  </div>
  <div class="alert alert-danger">
    <strong>Danger!</strong> You should <a href="#" class="alert-link">read this message</a>.
  </div>
  <div class="alert alert-primary">
    <strong>Primary!</strong> You should <a href="#" class="alert-link">read this message</a>.
  </div>
  <div class="alert alert-secondary">
    <strong>Secondary!</strong> You should <a href="#" class="alert-link">read this message</a>.
  </div>
  <div class="alert alert-dark">
    <strong>Dark!</strong> You should <a href="#" class="alert-link">read this message</a>.
  </div>
  <div class="alert alert-light">
    <strong>Light!</strong> You should <a href="#" class="alert-link">read this message</a>.
  </div>
</div>
</body>
</html>


关闭Alerts

如果要关闭警报消息,则必须向警报容器添加.alert-disableable类。然后将class="close"和data-dismiss ="alert"添加到链接或按钮元素(当您单击关闭符号时,警报框将关闭。)

示例:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Alerts</h2>
  <div class="alert alert-success alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Success!</strong> this alert box could indicate a successful or positive action.
  </div>
  <div class="alert alert-info alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Info!</strong> this alert box could indicate a neutral informative change or action.
  </div>
  <div class="alert alert-warning alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Warning!</strong> this alert box could indicate a warning that might need attention.
  </div>
  <div class="alert alert-danger alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Danger!</strong> this alert box could indicate a dangerous or potentially negative action.
  </div>
  <div class="alert alert-primary alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Primary!</strong> Indicates an important action.
  </div>
  <div class="alert alert-secondary alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Secondary!</strong> Indicates a slightly less important action.
  </div>
  <div class="alert alert-dark alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Dark!</strong> Dark grey alert.
  </div>
  <div class="alert alert-light alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Light!</strong> Light grey alert.
  </div>
</div>
</body>
</html>


Alerts动画

在关闭警报消息时,可以使用.fade和.show类添加淡入淡出效果。示例:
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Animated Alerts Example</h2>
  <div class="alert alert-success alert-dismissable fade show">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Success!</strong> this alert box could indicate a successful or positive action.
  </div>
  <div class="alert alert-info alert-dismissable fade show">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Info!</strong> this alert box could indicate a neutral informative change or action.
  </div>
  <div class="alert alert-warning alert-dismissable fade show">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Warning!</strong> this alert box could indicate a warning that might need attention.
  </div>
  <div class="alert alert-danger alert-dismissable fade show">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Danger!</strong> this alert box could indicate a dangerous or potentially negative action.
  </div>
  <div class="alert alert-primary alert-dismissable fade show">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Primary!</strong> Indicates an important action.
  </div>
  <div class="alert alert-secondary alert-dismissable fade show">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Secondary!</strong> Indicates a slightly less important action.
  </div>
  <div class="alert alert-dark alert-dismissable fade show">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Dark!</strong> Dark grey alert.
  </div>
  <div class="alert alert-light alert-dismissable fade show">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Light!</strong> Light grey alert.
  </div>
</div>
</body>
</html>