Bootstrap アラート

❮ 前章へ 次章へ ❯

アラート

Bootstrap は、定義済みアラートメッセージを作成する簡単な方法を提供します:

× 成功! このアラートボックスは、成功または積極的な行動を表します。
× 情報! このアラートボックスは、有益な変更や行動に中立であることを表します。
× 警告!このアラートボックスは、注意が必要とするかもしれない警告を表します。
× 危険! このアラートボックスは、危険または潜在的に負の行動を表します。

アラートは、4 つのコンテキストクラス、.alert-success.alert-info.alert-warning.alert-danger の内の何れか 1 つが後に続く、.alert クラスを使用して作成します:

<div class="alert alert-success">
  <strong>Success!</strong> Indicates a successful or positive action.
</div>

<div class="alert alert-info">
  <strong>Info!</strong> Indicates a neutral informative change or action.
</div>

<div class="alert alert-warning">
  <strong>Warning!</strong> Indicates a warning that might need attention.
</div>

<div class="alert alert-danger">
  <strong>Danger!</strong> Indicates a dangerous or potentially negative action.
</div>
Try it Yourself »

アラートを閉じる

アラートメッセージを閉じるには、リンクまたはボタンの要素に class="close"data-dismiss="alert" を追加します:

<div class="alert alert-success">
  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
  <strong>Success!</strong> Indicates a successful or positive action.
</div>
Try it Yourself »

aria-* 属性 と &times; の説明

スクリーンリーダーを使っている人のアクセシビリティを改善するためには、閉じるボタンを作成するときに aria-label="close" 属性を含める必要があります。

&times; (×) は、閉じボタンとして、文字 "x" よりも好まれる HTML エンティティです。


アニメ付きアラート

.fade.in クラスは、アラートメッセージを閉じるときにフェード効果を加えます:

<div class="alert alert-success fade in">
Try it Yourself »

練習問題で確認!

Exercise 1 »  Exercise 2 »  Exercise 3 »


完全な Bootstrap アラートリファレンス

すべての alert オプションの完全なリファレンスは、 Bootstrap JS アラートリファレンスをご覧ください。


❮ 前章へ 次章へ ❯