[Support request] How to apply the underline-on-hover-effect to menu-item-text?

Home Forums Support [Support request] How to apply the underline-on-hover-effect to menu-item-text?

Home Forums Support How to apply the underline-on-hover-effect to menu-item-text?

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2348250
    Sascha

    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,
    Sascha

    #2348702
    Ying
    Staff
    Customer Support

    Try 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;
    }
    #2350574
    Sascha

    Thanks, 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 occurs

    Hard 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,
    Sascha

    #2350907
    Ying
    Staff
    Customer Support

    Hum, 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;
    }
    #2350974
    Sascha

    Thank you, looks good!

    So now I’d like to have the active item underlined. How can I achieve this?

    #2351008
    Ying
    Staff
    Customer Support

    Use 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 the li > a::after selectors to make it more specific, otherwise, the effect will apply to list blocks in your content as well.

    #2351586
    Sascha

    Thanks a lot, looks perfect now πŸ™‚

    #2351895
    Ying
    Staff
    Customer Support

    Awesome πŸ™‚

    #2352256
    Sascha

    Hey 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,
    Sascha

    #2352710
    Ying
    Staff
    Customer Support

    It’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

    #2352730
    Sascha

    Oh, 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,
    Sascha

    #2352741
    Ying
    Staff
    Customer Support

    You are welcome πŸ™‚

    Underline only add to the parent menu items?

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.