-
mchammy75
I am trying to maintain the same site title and formatting on the sticky menu when scrolling. For some reason the site title disappears and the formatting changes such as margins and shifting menu items.
nav menu – https://jmp.sh/vU7Oyigi
sticky menu – https://jmp.sh/7HNsSLaM -
Hi there,
you would need to hook the site title into the navigation.
this topic explains how:https://generatepress.com/forums/topic/make-site-title-sticky-with-sticky-navigation/#post-2642689
The CSS may need some tweaking considering your off canvas toggle position. But I can help with that once the title is the nav
-
mchammy75
I made the change to add the PHP code snippet. Now the site title is showing twice on the navigation menu. See https://jmp.sh/oIXTFmxJ.
And when scrolling the hamburger menu is missing and formatting needs fixing. See https://jmp.sh/N1UUUsJO
-
Try adding this CSS:
@media(min-width: 769px) { nav:not(#sticky-navigation) .main-title { display: none; } nav#sticky-navigation .sticky-brand { margin-left: unset; margin-right: 40px; } #sticky-navigation .menu-toggle { display: block; order: -1; padding-left: 0; } #sticky-navigation .inside-navigation { justify-content: flex-start; padding-inline: 40px; } #sticky-navigation .main-nav { margin-inline: auto; } #sticky-navigation .main-title a { font-size: inherit; font-family: inherit; font-weight: inherit; text-transform: inherit; } }
-
mchammy75
This is looking a lot closer. The menu items still need to be shifted over to the left. See https://jmp.sh/9mcMhoUO
-
The menu items still need to be shifted over to the left. See
Do you want it to apply to both sticky nav and normal nav?
-
mchammy75
Yes. I would like the normal and sticky nav to be identical.
-
Add this CSS to the same media query:
.main-navigation:not(#sticky-navigation) div#primary-menu { margin-left: -40px; }
And remove
margin-right: 40px;
from this CSS:nav#sticky-navigation .sticky-brand { margin-left: unset; margin-right: 40px; }
-
mchammy75
I made the changes, but the menu move to the left only very slightly. For reference it looked something like this before https://jmp.sh/vU7Oyigi
-
The screenshot helps, I didn’t know you wanted it to look like this.
In this case, try this:
1. change this CSS:
.main-navigation:not(#sticky-navigation) div#primary-menu { margin-left: -40px; }
to:
.main-navigation div#primary-menu { margin-right: auto; }
2. Undo the #2 in my previous reply, add the
margin-right: 40px;
back to the CSS.3. Remove this CSS:
#sticky-navigation .main-nav { margin-inline: auto; }
-
mchammy75
Thanks. The formatting looks great now. However, now I notice when I start scrolling down initially the menu disappears. See the screenshot where it’s disappeared. https://jmp.sh/Cv9e1zQj
Then as I keep scrolling further down it fades in. It wasn’t behaving like this before. I’m looking to have it remain static at the top as I scroll down.
-
Fernando
I see. If that’s the case and you don’t want any transition, can you remove the codes added here, and disable the Sticky Nav in the Customizer? Once you’ve done this, let me know.
-
mchammy75
Which codes should I remove? I’ve modified so much CSS at this point.
-
Fernando
This one:
@media(min-width: 769px) { nav:not(#sticky-navigation) .main-title { display: none; } nav#sticky-navigation .sticky-brand { margin-left: unset; margin-right: 40px; } #sticky-navigation .menu-toggle { display: block; order: -1; padding-left: 0; } #sticky-navigation .inside-navigation { justify-content: flex-start; padding-inline: 40px; } #sticky-navigation .main-nav { margin-inline: auto; } #sticky-navigation .main-title a { font-size: inherit; font-family: inherit; font-weight: inherit; text-transform: inherit; } }
Plus the ones mentioned by Ying.
-
mchammy75
I’ve commented out the CSS and turned off Sticky Navigation here https://jmp.sh/YCgF5w4y.
Although the site title is now duplicated again and the navigation menu doesn’t move. So I’m not sure if this is what you meant.
What’s I’m trying to achieve is like this website http://www.coolmaterial.com where the navigation menu always hovers at the top consistently without fading in or out, even as you scroll down the page.
-
Fernando
What you did is correct.
Remove the PHP and CSS you added from here: https://generatepress.com/forums/topic/make-site-title-sticky-with-sticky-navigation/#post-2642689
Then, add this CSS:
header.site-header { position: sticky; top: 0; z-index: 100000; }
- You must be logged in to reply to this topic.