Skip to content
Advertisement

How to override CSS property while using a toggle button

JavaScript
JavaScript
JavaScript

I’m building a responsive top navbar with a toggle button, and trying to change a CSS property from display:none to display:block, but I can’t get it to work.

The menu is receiving the class “show” with the display:block property in it, from the toggle button (confirmed watching the code on dev tools of the browser), but the old display:none is not being overriden by the new property.

I’m a newbie and I have no idea what I’m doing. Is there any obvious code-hierarchy I’m missing?

The “nav-list” UL is the one receiving the “active” property, but its display property won’t change.

Advertisement

Answer

Just use !important in the .active class:

JavaScript

!important overrides the previous styling rules for this element, it adds importance to the property.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement