Animation for Collapsing Dropdowns within a Bootstrap Framework

I am facing an issue with the dropdown within the Navbar collapse. I want to implement a smooth animation for the dropdown/collapse instead of it abruptly appearing. The navbar-toggler button handles the animation perfectly, but the internal dropdown does not animate at all.

<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
 <i class="feather icon-menu"></i>

    <div class="navbar-collapse collapse w-100 order-1 order-md-0 dual-collapse2">
  <ul class="navbar-nav mr-auto">
    <li class="nav-item dropdown position-static">
      <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
           <i class="feather icon-menu"></i> Browse
         </a>
      <div class="dropdown-menu w-100" aria-labelledby="navbarDropdownMenuLink">
        <ul>
          {% for category in categories %}
          <li>
            <a href="{{ category.url }}" title="{{ category.prettify }} Discount Codes & Deals">{{ category.prettify }}</a>
          </li>
          {% endfor %}
        </ul>
      </div>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="https://www.vouchertoday.uk">
             <i class="feather icon-tag"></i>Stores
           </a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="https://www.vouchertoday.uk">
             <i class="feather icon-tag"></i>Latest
           </a>
    </li>
  </ul>
</div>

If you need a visual representation, check out this example - Click the dropdown internally.

Answer №1

To enhance the user experience, consider replacing the dropdown with a collapse effect and adding custom CSS to visualize the "collapsing" animation. Moreover, additional CSS tweaks were made to address any visual inconsistencies during the transition, specifically adjusting padding for the first and last child elements. Feel free to modify or remove these styles based on your preferences.

.dropdown-menu.collapsing {
    display: block;
}


/* Customize these rules according to your needs */
.dropdown-menu{
  padding: 0 !important;
}

.dropdown-menu .dropdown-item:first-child{
  margin-top: .5em;
}

.dropdown-menu .dropdown-item:last-child{
  margin-bottom: .5em;
}
/* Customize these rules according to your needs */
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
    <div class="navbar-collapse collapse w-100 order-1 order-md-0 dual-collapse2">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="https://www.vouchertoday.uk">Coupons</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="//codeply.com">Codeply</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
            </li>
            <li class="nav-item dropdown position-static">
              <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="collapse" data-target=".dropdown-menu" aria-haspopup="true" aria-expanded="false">
          <!-- ^^^^ Replacing dropdown with collapse by using the same data-target as the button class "navbar-toggler" -->            
                Dropdown link
              </a>
              <div class="dropdown-menu w-100 collapse" aria-labelledby="navbarDropdownMenuLink">
                                          <!--- ^^^^^ Adding this class here -->
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </li>
        </ul>
    </div>
    <div class="mx-auto order-0">
        <a class="navbar-brand mx-auto" href="#">Navbar 2</a>
    </div>
    <div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
        <ul class="navbar-nav ml-auto">
            <li class="nav-item">
                <a class="nav-link" href="#">Right</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
            </li>
        </ul>
    </div>

</nav>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Override the default HTML style overflow to hidden with Material UI Swipable Drawer

Currently, I'm utilizing the Material UI SwipableDrawer component which has an unexpected drawback of causing the scrollbar to disappear when the drawer is displayed. This issue overrides my specified style of "overflow-y: scroll" on the Html tag and ...

Scraping Google Places using Beautifulsoup for extracting reviews

My objective is to extract User reviews from Google Places reviews, as the API only provides the 5 most helpful reviews. I am using Beautifulsoup to retrieve four key pieces of information: 1) Name of the reviewer 2) Date the review was written 3) Rating ( ...

What could be causing the @each statement in SASS to not function properly in Next.js?

I am struggling with my SCSS files and color scheme colors.scss @import './variables'; $colors: ( p: $color-primary, s: $color-secondary, t: $color-tertiary, q: $color-quartary, ); @each $name, $hsl in $colors { .c-#{name} { colo ...

Tips for incorporating a dynamic CSS style sheet into a standalone xhtml document

I am faced with the task of incorporating two CSS classes into a single xhtml. For instance: Take, for example, display.xhtml, which will be utilized by two different applications, each requiring its own CSS styling. This means that if display.xhtml is ...

Please assist in changing the text color of the right side of my navigation bar to white with the help of Bootstrap

Is there a way to change the text color of my nav-bar to white, while keeping the background as 'primary-subtle' with Bootstrap? How can I override Bootstrap's default functions using CSS when combining these two styles? Here is the code sn ...

WordPress Header Display Issue on Mobile and Tablet Devices: What You Need to Know

I'm facing an issue with the header and footer being cut off on mobile devices. When viewed on a tablet or phone, the header doesn't display across the full width of the screen. This problem arises because the Wordpress theme was created in 2010 ...

Tips for setting a uniform width for all bars in apexcharts bar column width

When working with dynamic data, the length of the data should also be variable. For instance, if the data has a length of 24, the column width should be 35px; similarly, even if the data has a length of 2, the column width should still be 35px. Apexchart ...

Stop images from flipping while CSS animation is in progress

I've been developing a rock paper scissors game where two images shake to mimic the hand motions of the game when a button is clicked. However, I'm facing an issue where one of the images flips horizontally during the animation and then flips bac ...

The collapsed feature of the Bootstrap 4 Navbar is not functioning as

Recently, I delved into the world of Bootstrap 4 and decided to create a collapsing menu. Everything seemed to be working fine when I clicked the button and saw the content display perfectly. However, things took a turn for the worse when I tried to collap ...

What is the best way to verify if a CSS property is supported?

Is it possible to determine whether a specific CSS property is supported? For instance, I am planning to create an animation on a webpage using the perspective-origin property, but if it's not supported, I would opt to adjust the size instead. ...

A guide on extracting keywords from the tynt API using JavaScript

Looking to extract the inbound keyword from an API: What would be the best way to use JavaScript to extract and display the value of the inbound keyword from this API? ...

Ways to prevent users from manually inputting dates in date fields

I am currently developing an application and I need to prevent users from manually entering a date in the type=date field on the HTML page. I want to restrict users to only be able to select a date from the calendar display, which is in the format MM/DD/YY ...

Unable to write to csv file in UTF-8 using PHP fwrite, experiencing issues

Looking for assistance with handling PHP fwrite as CSV file is displaying incorrect characters. The output appears like this: općšpšćšćšp ćpšćpšćp šćpšćpšć This is the PHP code being used fo ...

Why is the option value not visible in the dropdown selection list?

On my website, I am trying to use a date range to aggregate data from MySQL and display it based on the selected time frame. However, I am facing an issue where the values for each option in the drop-down menus are not showing up. Below is the PHP code I a ...

What is the best way to configure an EmailId validator in Angular 6 to be case insensitive?

My register and login page include a form validator pattern matching for the registration form. this.registerForm = this.formBuilder.group({ firstName: ['', Validators.required], emailId: ['', [Validators.required, Validators.patt ...

Change the default action of the hyperlink to initiate an AJAX request instead

Recently, I've been experimenting with Bootstrap on my local machine to create a website, and everything has been going well. However, I've encountered a peculiar issue that I'm not sure is related to Bootstrap or something else. My site co ...

Creating multiple "read more" and "read less" buttons on a single webpage

Can you figure out what's going wrong here? I assigned each one a separate ID, but it's still not functioning properly in my code. I need to get this fixed for an assignment that's due in a few days, so any help is appreciated! function r ...

Tips on how to ensure that an onClick JS function only runs when radio buttons are selected

I have implemented the formslider library for a form on my website. In the demo, the slide transitions to the next set of questions based on a click event triggered by radio buttons (answers). However, when I attempted to include checkboxes for users to s ...

What is the best way to display a div in Chrome without allowing any user interactions?

I currently have a <div> placed on top of my webpage that follows the mouse cursor. Occasionally, users are able to move the mouse quickly enough to enter the tracking <div>. Additionally, this <div> sometimes prevents users from clicking ...

Discovering hidden files within appsettings.json in ASP.NET Core 6 using Program.cs

Within Appsettings.json, the code resembles the following: { "Project": { "ConnectionString": "Data Source=(local)\SQLSERVER; Database=MyCompany; Persist Security Info=false; User ID='sa'; Password='sa ...