Archived topic
Problems with menu item css animations
4 replies · Started by David on April 1, 2021
Hey there,
I tweaked the primary menu a bit with CSS snippets you guys provided.
Two problems:
1) When I use CSS animations on the menu items with this code the underline will be too small (looks like is width is not including the dropdown symbol): https://share.getcloudapp.com/geub0Ygx
The code I used:
/* - Menubar animations */
@media (min-width: 769px) {
.main-navigation .menu > .menu-item > a::after {
content: "";
position: absolute;
right: 0;
left: 50%;
bottom: 15px;
-webkit-transform: translate3d(-50%,0,0);
transform: translate3d(-50%,0,0);
display: block;
width: 0;
height: 2px;
background-color: currentColor;
transition: 0.3s width ease;
}
.main-navigation .menu > .menu-item.current-menu-item > a::after,
.main-navigation .menu > .menu-item.current-menu-ancestor > a::after,
.main-navigation .menu > .menu-item > a:hover::after {
width: 50%;
}
}
2) I use a CTA menu item (class .nav-button) that gets affected by the menu animations. What is the best way to exclude it from the css selector in the code I just pasted?
Thanks for any help!
Best, David
Hi there,
1. In your CSS the very last property is width: 50%; you can set that to a large value to make the line extend. eg. width: 100%; will cover the entire menu item.
2. Add this CSS to exclude the button:
.main-navigation .menu > .menu-item.nav-button > a::after {
display: none !important;
}
Amazing, David. Thanks.
There was a typo in my code. So if someone needs the working code here it is:
/* – Menubar animations */
@media (min-width: 769px) {
.main-navigation .menu > .menu-item > a::after {
content: "";
position: absolute;
right: 0;
left: 50%;
bottom: 10px;
-webkit-transform: translate3d(-50%,0,0);
transform: translate3d(-50%,0,0);
display: block;
width: 0;
height: 2px;
background-color: currentColor;
transition: 0.3s width ease;
}
.main-navigation .menu > .menu-item.current-menu-item > a::after,
.main-navigation .menu > .menu-item.current-menu-ancestor > a::after,
.main-navigation .menu > .menu-item > a:hover::after {
width: 80%;
}
}
/* -- not on nav-button */
.main-navigation .menu > .menu-item.nav-button > a::after {
display: none !important;
}
Glad to be of help
Thanks!