← Back to Bootstrap Course | Chapter 7: Components — Cards & Alerts | Lesson 5 of 7

बंद होने वाले Alerts

एक dismissible alert में एक close button है जो इसे page से remove करता है।

In this page:

  1. Dismissible Alerts
Syntax
markup
<div class="alert alert-warning alert-dismissible fade show" role="alert">
  Message
  <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>

Dismissible Alerts

.alert-dismissible, data-bs-dismiss="alert" वाला एक .btn-close button, और typically animation के लिए .fade .show add करें। button click होने पर JavaScript bundle alert remove करता है। Close button को एक aria-label दें।

Note: smooth fade-out के लिए fade और show साथ इस्तेमाल करें।

उदाहरण: Dismissible alerts

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-3">
<div class="container">
  <div class="alert alert-warning alert-dismissible fade show" role="alert">
    <strong>Heads up!</strong> Click the X to dismiss this alert.
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  </div>
</div>
</body>
</html>
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. alert-dismissible padding भूल जाना
  2. data-bs-dismiss missing होना
  3. close button पर कोई aria-label नहीं
चैप्टर सारांश
  • alert-dismissible room add करता है
  • data-bs-dismiss="alert" वाला btn-close
  • fade show animate करता है
  • JS bundle चाहिए
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.