Dropdown Basics

Back

Loading concept...

Bootstrap Dropdowns: The Magic Menu Box 🎁

The Story of the Hidden Menu

Imagine you have a toy box. From the outside, it looks like a simple box with a lid. But when you open the lid—WOW!—there are toys inside! That’s exactly what a dropdown is in Bootstrap.

A dropdown is like a magic box that hides a menu. You click a button, and poof—a list of choices appears!


🎯 What You’ll Learn

  1. Dropdowns – The magic box itself
  2. Dropdown Menu – The container that holds all choices
  3. Dropdown Items – The individual choices inside
  4. Dropdown Active Item – The “currently selected” choice
  5. Dropdown Disabled Item – Choices you can’t click
  6. Dropdown Direction Variants – Menus that pop up, left, or right!

1. Dropdowns: The Magic Box

What is it?

A dropdown is a button that shows a hidden menu when clicked. Think of it like a surprise drawer in a desk—click and it opens!

The Basic Structure

<div class="dropdown">
  <button class="btn btn-primary
    dropdown-toggle"
    data-bs-toggle="dropdown">
    Pick a Fruit
  </button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item"
      href="#">Apple</a></li>
    <li><a class="dropdown-item"
      href="#">Banana</a></li>
  </ul>
</div>

🔑 Key Parts

Class What It Does
dropdown The container box
dropdown-toggle Makes button clickable
data-bs-toggle Tells Bootstrap “this is a dropdown”

2. Dropdown Menu: The Container

What is it?

The dropdown-menu is like a lunchbox that holds all your food choices. It’s the white box that appears when you click.

graph TD A["Click Button"] --> B["Dropdown Menu Opens"] B --> C["See All Items Inside"] C --> D["Pick One!"]

Example

<ul class="dropdown-menu">
  <li><a class="dropdown-item"
    href="#">Choice 1</a></li>
  <li><a class="dropdown-item"
    href="#">Choice 2</a></li>
  <li><a class="dropdown-item"
    href="#">Choice 3</a></li>
</ul>

The dropdown-menu class:

  • Creates a white background
  • Adds nice rounded corners
  • Adds a subtle shadow
  • Positions it below the button

3. Dropdown Items: Your Choices

What is it?

Each thing you can click inside the menu is a dropdown-item. Like each candy in a candy jar!

Simple Example

<a class="dropdown-item" href="#">
  Edit Profile
</a>
<a class="dropdown-item" href="#">
  Settings
</a>
<a class="dropdown-item" href="#">
  Logout
</a>

🎨 What Makes Items Special

  • They change color when you hover
  • They’re clickable links or buttons
  • Each one does something different!

Real Life Example:

  • Instagram’s three dots menu → dropdown items!
  • Your phone’s settings menu → dropdown items!

4. Dropdown Active Item: “You Are Here!”

What is it?

Sometimes you want to show which item is currently selected—like putting a gold star on your favorite toy!

<a class="dropdown-item active"
  href="#">
  Currently Selected
</a>

The Magic

graph TD A["Regular Item"] --> B["Gray Text"] C["Active Item"] --> D["Blue Background!"] D --> E["Shows Current Choice"]

Example: A Color Picker

<ul class="dropdown-menu">
  <li><a class="dropdown-item"
    href="#">Red</a></li>
  <li><a class="dropdown-item active"
    href="#">Blue ✓</a></li>
  <li><a class="dropdown-item"
    href="#">Green</a></li>
</ul>

The active class adds a blue background to show “this is the current choice!”


5. Dropdown Disabled Item: “No Touch!”

What is it?

Sometimes a choice isn’t available. Like a toy that’s broken—you can see it, but you can’t play with it.

<a class="dropdown-item disabled"
  href="#">
  Coming Soon...
</a>

What Happens?

Normal Item Disabled Item
Click works Click doesn’t work
Normal color Faded/gray color
Cursor: pointer Cursor: not-allowed

Real Example

<ul class="dropdown-menu">
  <li><a class="dropdown-item"
    href="#">Free Plan</a></li>
  <li><a class="dropdown-item"
    href="#">Basic Plan</a></li>
  <li><a class="dropdown-item disabled"
    href="#">Pro Plan (Locked)</a></li>
</ul>

The disabled item looks faded and won’t respond to clicks!


6. Dropdown Direction Variants: Which Way to Pop?

The Problem

What if your dropdown is at the bottom of the screen? The menu would go off the screen! We need it to pop UP instead.

The Four Directions

graph TD A["dropdown"] --> B["Goes DOWN ⬇️"] C["dropup"] --> D["Goes UP ⬆️"] E["dropstart"] --> F["Goes LEFT ⬅️"] G["dropend"] --> H["Goes RIGHT ➡️"]

Code Examples

Default (Down):

<div class="dropdown">
  <!-- Opens below -->
</div>

Dropup (Up):

<div class="dropup">
  <!-- Opens above -->
</div>

Dropstart (Left):

<div class="dropstart">
  <!-- Opens to the left -->
</div>

Dropend (Right):

<div class="dropend">
  <!-- Opens to the right -->
</div>

When to Use Each

Direction Use When…
dropdown Button is at top/middle of page
dropup Button is at bottom of page
dropstart Button is on right side
dropend Button is on left side

🎮 Putting It All Together

Here’s a complete example with everything we learned:

<div class="dropdown">
  <button class="btn btn-success
    dropdown-toggle"
    data-bs-toggle="dropdown">
    My Account
  </button>
  <ul class="dropdown-menu">
    <li>
      <a class="dropdown-item active"
        href="#">Dashboard</a>
    </li>
    <li>
      <a class="dropdown-item"
        href="#">Profile</a>
    </li>
    <li>
      <a class="dropdown-item"
        href="#">Settings</a>
    </li>
    <li><hr class="dropdown-divider"></li>
    <li>
      <a class="dropdown-item disabled"
        href="#">Admin (No Access)</a>
    </li>
    <li>
      <a class="dropdown-item text-danger"
        href="#">Logout</a>
    </li>
  </ul>
</div>

🌟 Quick Summary

Concept Class What It Does
Container dropdown Wraps everything
Button dropdown-toggle Opens the menu
Menu dropdown-menu Holds all items
Item dropdown-item Each clickable choice
Selected active Shows current selection
Locked disabled Can’t be clicked
Pop Up dropup Menu goes upward
Pop Left dropstart Menu goes left
Pop Right dropend Menu goes right

🎉 You Did It!

You now understand Bootstrap Dropdowns! Remember:

  1. Dropdown = Magic box with hidden menu
  2. Menu = The container that appears
  3. Items = Things you can click
  4. Active = “Currently selected”
  5. Disabled = “Can’t touch this”
  6. Directions = Up, down, left, right!

Now go build something amazing with your new dropdown superpowers! 🚀

Loading story...

Story - Premium Content

Please sign in to view this story and start learning.

Upgrade to Premium to unlock full access to all stories.

Stay Tuned!

Story is coming soon.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.