How can I make the navigation bar link remain red when the dropdown is open, even if the user is not hovering over it in Webflow?

Published on
September 22, 2023

To make the navigation bar link remain red when the dropdown is open, even if the user is not hovering over it in Webflow, you can use the combination of Webflow's built-in interactions and custom CSS. Here are the steps to achieve this:

  1. Create your dropdown menu:
  • Add a dropdown or navbar component to your page.
  • Add the necessary links to the dropdown menu.
  • Style the links as desired, including the red color for the active link.
  1. Configure the interaction:
  • Select the dropdown or navbar component and go to the Interactions panel.
  • Click on the "+ Add an interaction" button.
  • Choose the trigger for the interaction. For example, you can select "Mouse click/tap" to activate the dropdown.
  • Select the element that triggers the interaction. In this case, choose the navigation bar link that opens the dropdown.
  • Under "Affect Different Element(s)", click "+ Add an action."
  • Choose the action "Element trigger" and select the dropdown menu or any element inside it.
  • Add an action for changing the appearance of the dropdown or target element. For example, you can set the background color of the dropdown to red.
  1. Customize the CSS:
  • Open the site settings and navigate to the Custom Code section.

  • Click the "Add Custom Code" button and choose where you want to insert the code (before or before ).

  • Add the following CSS code:
    ```css

    ```

    This CSS code targets the navigation link with the class .nav-link inside a dropdown when it is open .w-dropdown-open and applies the red color to it.

  1. Publish your site:
  • Once done, make sure to publish your site for the changes to take effect.

Now, when a user clicks on the navigation bar link to open the dropdown, the link will remain red even if the user is not hovering over it.

Additional CSS customization can be applied depending on your specific design requirements.