• Resolved theye

    (@theye)


    Hi all,

    For my header, I would like to change the underlining in the following ways:
    – add underline for the current menu item
    – remove underline of menu item on hover, and add greying out of menu item on hover
    – remove the underline on the site title (I would still like it to link to the home page).

    I have tried to add underlining for the current menu item by adding the following custom css:

    .builder-item--primary-menu .nav-menu-primary>.primary-menu-ul li.current-menu-item>a {
        text-decoration: underline !important;
    }

    This doesn’t seem to have any effect. Is there any other way to customize the underlining?

    • This topic was modified 3 years, 9 months ago by theye.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Moderator Kathryn Presner

    (@zoonini)

    Hi @theye – not sure where you got that CSS but it’s not something that’ll work in this theme.

    Let’s look at your items one by one:

    – remove the underline on the site title (I would still like it to link to the home page).

    This CSS should remove the default underline and hover underline on the site title:

    /* Site title - remove underline */
    .wp-block-site-title a,
    .wp-block-site-title a:hover, 
    .wp-block-site-title a:focus {
      text-decoration: none;
    }

    – remove underline of menu item on hover, and add greying out of menu item on hover

    This should do the trick. You can modify the shade of grey as you like:

    /* Menu hover & focus */
    .wp-block-navigation .wp-block-navigation-item a:hover, 
    .wp-block-navigation .wp-block-navigation-item a:focus {
      text-decoration: none;
      color: #a1a1a1;
    }

    – add underline for the current menu item

    The Navigation Block does not come with a class for the current page, so there’s no automated way with CSS to apply an underline to all current menu items at once. There is an open enhancement issue for this in GitHub.

    That said, since you have only three pages in your menu, you could target them individually. In order to do that, you’d first need to add a custom class to each menu item, like this example for your About page:

    Editor beta Self hosted Test WordPress

    Once you’ve added a custom class to each of your three pages – for example, they could be musiek / about / contact – let me know and I can take a look at the necessary custom CSS to have those underlined only on the relevant “current” page.

    The Navigation Block does have a class for the current page, so something like this should work to underline the current menu item:

    
    .wp-block-navigation-item.current-menu-item > a {
      text-decoration: underline;
    }
    
    Moderator Kathryn Presner

    (@zoonini)

    @uxl You are absolutely right, thanks for noticing that, don’t know how I missed it!

    @theye You can ignore my suggestion about adding a custom class, as Uxl’s CSS above should do the trick. Let us know how it goes, and please mark this thread as resolved if all your customizations have been taken care of.

    Default is underlined.
    How to cancel the underline, the underline only appears when the mouse is hovered?

    Moderator Kathryn Presner

    (@zoonini)

    @ninglexi Looks like you got a reply on your own thread. If you need further help with it, please continue there.

    @theye Are you all set?

    Thread Starter theye

    (@theye)

    Hi guys,

    Sorry for my delayed reply. I was on holiday, didn’t check my messages. The solution by @uxl worked!

    However, I still have two questions:

    1) how can I add greying out of a menu item on hover instead of underlining on hover?

    2) How can I remove the underline on the site title (I would still like it to link to the home page)?

    Thanks!

    • This reply was modified 3 years, 8 months ago by theye.
    Moderator Kathryn Presner

    (@zoonini)

    Hi @theye I think I already answered your two questions above and provided CSS – would you like to have another look?

    https://ww.wp.xz.cn/support/topic/adding-underline-to-current-menu-item/?view=all#post-15918102

    Let me know if that does the trick.

    Thread Starter theye

    (@theye)

    Hi Kathryn, sorry I totally overlooked your first comment. Thanks for the elaborate response, this works!

    Moderator Kathryn Presner

    (@zoonini)

    Awesome, glad to hear it, and you’re very welcome!

    Thread Starter theye

    (@theye)

    I have two more questions:

    1) is there a way to grey out the site title on hover?
    2) is there a way to underline the site title when it is the current page?

    Moderator Kathryn Presner

    (@zoonini)

    1) is there a way to grey out the site title on hover?

    This should do it. You can replace the colour code with whatever you prefer:

    
    /* Site title - grey on hover */
    .wp-block-site-title a:hover {
      color: #666666;
    }

    2) is there a way to underline the site title when it is the current page?

    Could you explain what you mean a bit more by the “current page”? The Site Title links to the homepage, so did you want it underlined only on the homepage?

    Thread Starter theye

    (@theye)

    Hi Kathryn, thanks for your answer on the first question.

    About the second question, yes, I would like to underline it, only on the home page.

    Thanks again !

    Moderator Kathryn Presner

    (@zoonini)

    @theye If you want to keep the site title underlined on the homepage, remove this CSS I gave you previously:

    /* Site title - remove underline */
    .wp-block-site-title a,
    .wp-block-site-title a:hover, 
    .wp-block-site-title a:focus {
      text-decoration: none;
    }

    And use this instead:

    /* Site title - remove underline everywhere except homepage */
    body:not(.home) .wp-block-site-title a,
    body:not(.home) .wp-block-site-title a:hover, 
    body:not(.home) .wp-block-site-title a:focus {
      text-decoration: none;
    }

    If you need help with something else, please feel free to start a new thread. Thanks!

    Thread Starter theye

    (@theye)

    Hi @zoonini , thanks a lot, that’s exactly what I meant! I looks perfect now.

    Moderator Kathryn Presner

    (@zoonini)

    Awesome, glad to hear it!

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Adding underline to current menu item’ is closed to new replies.