I need help adding a sliding animation to the main menu items when the cursor hovers over them.
Currently, there’s an underline on hover, but it’s missing any smooth animation.
Could someone help me implement a smooth sliding animation to it ?
To add a smooth sliding animation for the underline on hover for your main menu items, you can use CSS transitions and pseudo-elements like ::before or
::after. This will allow the underline to smoothly slide in from the left or right.
Follow these steps:
Online Store > Themes > Actions > Edit Code > Assets > Open your CSS or SCSS file (usually theme.scss.liquid or base.css).
Paste the code at the end of your CSS file.
How you can implement it:
First, locate the class or element ID for your main menu items in your theme’s CSS.
You can use the :;after pseudo-element to create the underline and apply a transition for the sliding effect.
example css code that should create a sliding underline animation when the user hovers over the main menu items:
/* Main menu item base styles */
.main-menu-item {
position: relative;
display: inline-block;
padding-bottom: 5px;
}
/* Underline styles - initially hidden */
.main-menu-item::after {
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 0;
height: 2px;
background-color: #000; /* Customize the underline color */
transition: width 0.4s ease;
}
/* Hover effect - sliding animation */
.main-menu-item:hover::after {
width: 100%; /* The underline expands to full width */
}
Replace .main-menu-item with the actual class used for your main menu items in your theme if it differs.
I managed to helIfp you then, don’t forget to Like it and Mark it as Solution!