← Back to Bootstrap Course | Chapter 6: Components — Navigation | Lesson 4 of 7

Dropdowns क्या हैं

Dropdowns एक button click होने पर links का एक menu reveal करते हैं।

In this page:

  1. Dropdowns
Syntax
markup
<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown">Menu</button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Item</a></li>
  </ul>
</div>

Dropdowns

data-bs-toggle="dropdown" वाले एक trigger को .dropdown में एक .dropdown-menu list के साथ wrap करें। Directions .dropup, .dropend, या .dropstart से बदली जा सकती हैं, और alignment .dropdown-menu-end से।

Items .dropdown-item इस्तेमाल करते हैं, और dividers और headers इन्हें organise करते हैं।

इसे Popper के साथ JS bundle चाहिए।

Note: Dropdown बिना extra JavaScript code के काम करता है, सिर्फ bundle चाहिए।

उदाहरण: Dropdowns

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="dropdown">
    <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Actions</button>
    <ul class="dropdown-menu">
      <li><h6 class="dropdown-header">Edit</h6></li>
      <li><a class="dropdown-item" href="#">Rename</a></li>
      <li><a class="dropdown-item" href="#">Duplicate</a></li>
      <li><hr class="dropdown-divider"></li>
      <li><a class="dropdown-item text-danger" href="#">Delete</a></li>
    </ul>
  </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. data-bs-toggle missing होना
  2. JS bundle भूल जाना
  3. menu को dropdown wrapper के बाहर रखना
चैप्टर सारांश
  • trigger पर data-bs-toggle="dropdown"
  • dropdown-menu और dropdown-item
  • dropup, dropend, dropstart variants मिलते हैं
  • 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.