- This topic has 11 replies, 2 voices, and was last updated 1 year, 6 months ago by Ying.
-
AuthorPosts
-
September 20, 2022 at 3:05 am #2348250Sascha
Hey there,
Iβd like to replicate the animated-underline-effect from the nav-menu on this site (source) to the one on that site (target).
Currently, I have applied this CSS to the customizer, but the underline-effect applies to the menu-items, but not to the text inside the items, like they do on source-site:
li > a::after { bottom: 0; content: ""; display: block; height: 2px; left: 0%; position: absolute; background: var(--accent); transition: width 0.2s ease 0s, left 0.1s ease 0s; width: 0; } li > a:hover::after, li > a.active-nav::after { width: 100%; left: 0; }
Can you please help me to replicate the underline-effect appropriately?
Thank you in advance and kind regards,
SaschaSeptember 20, 2022 at 9:55 am #2348702YingStaffCustomer SupportTry change this CSS:
li > a::after { bottom: 0; content: ""; display: block; height: 2px; left: 0%; position: absolute; background: var(--accent); transition: width 0.2s ease 0s, left 0.1s ease 0s; width: 0; } li > a:hover::after, li > a.active-nav::after { width: 100%; left: 0; }
to this:
.main-navigation li > a::after { bottom: 10px; content: ""; display: block; height: 2px; left: 0; position: absolute; background: var(--accent); transition: width 0.2s ease 0s, left 0.1s ease 0s; width: 0; } .main-navigation li > a:hover::after, .main-navigation li > a.active-nav::after { width: calc(100% - 40px); left: 50%; transform: translatex(-50%); bottom: 10px; }
September 22, 2022 at 7:05 am #2350574SaschaThanks, Ying, but now 2 issues occur:
1. The underline is not going from left to right, instead it goes from center to left+right
2. The previous full-width underline effect applied to the menu-items still occursHard to explain in words, so I recorded a brief screencast.
Can you please help me to fix this?
Thank you in advance and kind regards,
SaschaSeptember 22, 2022 at 10:32 am #2350907YingStaffCustomer SupportHum, then let’s switch back to your original CSS, then add this CSS:
.main-navigation .main-nav ul li a { padding-left: 0; padding-right: 0; margin-left: 20px; margin-right: 20px; position: relative; }
September 22, 2022 at 12:00 pm #2350974SaschaThank you, looks good!
So now I’d like to have the active item underlined. How can I achieve this?
September 22, 2022 at 1:10 pm #2351008YingStaffCustomer SupportUse this selector for hover and current menu item:
.main-navigation .main-nav ul li > a:hover::after, .main-navigation .main-nav ul li[class*="current-menu-"] > a::after
I would suggest adding
.main-navigation .main-nav ul
before all theli > a::after
selectors to make it more specific, otherwise, the effect will apply to list blocks in your content as well.September 23, 2022 at 6:03 am #2351586SaschaThanks a lot, looks perfect now π
September 23, 2022 at 11:05 am #2351895YingStaffCustomer SupportAwesome π
September 24, 2022 at 2:14 am #2352256SaschaHey there,
sorry for re-opening this ticket again.
The CSS is working well on this site (via Customizer), but not on that one (via Simple CSS).
How come?
Also: How to prevent the underline-effect to work on the last menu-item? Should work on all menu-items except for the last one π
Thank you in advance and kind regards,
SaschaSeptember 24, 2022 at 11:59 am #2352710YingStaffCustomer SupportIt’s working fine on the link you provided.
To remove the effect from the last menu item, change this selector
.main-navigation .main-nav ul li > a:hover::after, .main-navigation .main-nav ul li[class*="current-menu-"] > a::after
to:
.main-navigation .main-nav ul li:not(:last-child) > a:hover::after, .main-navigation .main-nav ul li[class*="current-menu-"]:not(:last-child) > a::after
September 24, 2022 at 12:34 pm #2352730SaschaOh, you were right π
I have placed the post, where the CSS is added to, below the “Blog” menu item, but it looks a bit awkward, as you can see on this screenshot (link to the post)
I’d like to prevent the underline-effect for active menu-items, which contain sub-menu-items, to expand to the full-item width. Instead, I’d like to have it underline only below the text of these items.
Is this possible, too?
By the way: Your support is phenomenal, thank you sooo much for your help π
Thank you in advance and kind regards,
SaschaSeptember 24, 2022 at 12:55 pm #2352741YingStaffCustomer SupportYou are welcome π
Underline only add to the parent menu items?
-
AuthorPosts
- You must be logged in to reply to this topic.