Open In App

Bootstrap 5 Dropdowns Directions

Bootstrap 5 Dropdowns Directions are used to change the direction in which we want the dropdown to pop up. The arrow direction is changed based on the direction set for the dropdown to appear.

Bootstrap 5 Dropdowns Directions:



Syntax:

<div class="btn-group dropdown-direction-class">
    ...
</div>

Below examples illustrate the Bootstrap 5 Dropdowns Directions:



Example 1: In this example, we will set the direction of the dropdown to show upwards.




<!DOCTYPE html>
<html>
  
<head>
    <link href=
          rel="stylesheet" 
          integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" 
            crossorigin="anonymous">
    <script src=
            integrity=
"sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" 
            crossorigin="anonymous">
    </script>
</head>
  
<body>
    <div class="container">
        <h1 class="text-success">
            GeeksforGeeks
        </h1>
        <h2>
            Bootstrap 5 Dropdowns Directions
        </h2>
        <div class="btn-group dropup">
            <button type="button" 
                    class="btn-success dropdown-toggle"
                    data-bs-toggle="dropdown">
                Select Course from GeeksforGeeks
            </button>
            <div class="dropdown-menu dropdown-menu-end ">
                <a class="dropdown-item" href="#">
                    C Programming
                </a>
                <a class="dropdown-item" href="#">
                    C++ Programming
                </a>
                <a class="dropdown-item" href="#">
                    Java Programming
                </a>
            </div>
        </div>
    </div>
  
</body>
  
</html>

Output:

 

Example 2: In this example, we will set the direction of the dropdown to show on the right.




<!DOCTYPE html>
<html>
  
<head>
    <link href=
          rel="stylesheet" 
          integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" 
            crossorigin="anonymous">
    <script src=
            integrity=
"sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" 
            crossorigin="anonymous">
    </script>
</head>
  
<body>
    <div class="container">
        <h1 class="text-success">
            GeeksforGeeks
        </h1>
        <h2>
            Bootstrap 5 Dropdowns Directions
        </h2>
        <div class="btn-group dropend">
            <button type="button" 
                    class="btn-success dropdown-toggle" 
                    data-bs-toggle="dropdown">
                Select Course from GeeksforGeeks 
            </button>
            <div class="dropdown-menu dropdown-menu-end ">
                <a class="dropdown-item" 
                   href="#">
                    C Programming
                </a>
                <a class="dropdown-item" 
                   href="#">
                    C++ Programming
                </a>
                <a class="dropdown-item" 
                   href="#">
                    Java Programming
                </a>
            </div>
        </div>
    </div>
  
</body>
  
</html>

Output:

 

Reference: https://getbootstrap.com/docs/5.0/components/dropdowns/#directions


Article Tags :