Site logo

Archived topic

Underline menu navigation on hover and current

15 replies · Started by Dennis on August 29, 2017

Viewing posts 1–15 of 16

Hey,

what do I have to insert into the CSS field to get a simple underline that you see on most websites nowadays? I also want the current page to be underlined.

So basically I want the current page in the menu to be underlined and underline on hover. I've tried modifying the code from the link but it ended up weird on mobile and tablets..

Also, I don't want any animation with it.

OK then scratch that then just use this:

@media (min-width:769px) {
    .main-navigation .main-nav ul li[class*="current-menu-"] > a {
        border-bottom: 2px solid #ffffff;
    }
}

Awesome! I didn't get quite the results I wanted from your code so I kinda assembled the one you posted before (from the link) and the new one:

@media (min-width: 769px) {
	.main-navigation .menu > .menu-item > a::after {
    content: "";
    position: absolute;
    right: 50%;
    left: 50%;
    bottom: 1px;
    transform: translateX(-50%);
    height: 4px;

    background-color: currentColor;
}
.main-navigation .menu > .menu-item.current-menu-item > a::after{
    width: 50%;
}
}

What do you think about that code? It works great on desktop but I was trying to get it to work on mobile (with a max width of 768) but the underlining is always out of place.

Any ideas?

Code looks good.

Mobile is a bit tricky. Can you show me what you have so far?

I actually settled for a different approach which works great on mobile too.

However, I changed the text colour of the primary navigation and now the text next to the burger menu on mobile has the same colour. Is it possible to make it black instead of the text colour specified in the customize menu?

hey, didnt work!

Can you link me to the site?

Looks like you removed the menu text?

The toggle can be changed like this:

@media (max-width: 768px)
    .mobile-header-logo .main-navigation.mobile-header-navigation .menu-toggle {
        color: #000000;
    }
}

yep that work! thank you so much for your patience. :)
had to add one bracket after the first line

just out of curiosity, how do i tackle learning CSS best? where do I start? any tips?

I learned from doing the free course here: https://www.codecademy.com/

Then it's just using the developer tool of your browser :)

hi all ;)

i used this code:

@media (min-width: 769px) {
	.main-navigation .menu > .menu-item > a::after {
    content: "";
    position: absolute;
    right: 50%;
    left: 50%;
    bottom: 1px;
    transform: translateX(-50%);
    height: 4px;

    background-color: currentColor;
}
.main-navigation .menu > .menu-item.current-menu-item > a::after{
    width: 50%;
}
}

Everything works well until it comes to the dropdown menu.
https://prnt.sc/1o238fg

Is it possible to align the underline so that it appears exclusively below the menu text?

I want it to be like this:
https://prnt.sc/1o24igh

This archived topic is closed to new replies.