- This topic has 14 replies, 3 voices, and was last updated 2 years, 11 months ago by
Fernando.
-
AuthorPosts
-
April 1, 2023 at 2:48 pm #2592441
Mel
Hi, I am using the myPet template, I would like to create a sticky header (for desktop only) including top bar (widget), logo (same size), menu, and background image (wave). How do I do this please, and also add enough space on the bottom to fit the submenu?
The sticky header should look the same as when it is not sticky.Thanks
MelApril 1, 2023 at 5:26 pm #2592524Ying
StaffCustomer SupportHi Mel,
It’s not possible to include the waves as the wave is inside the content area, not in the header area.
However, you can use this CSS to make the header sticky:
.header-wrap { position: fixed; top: 0; }April 1, 2023 at 9:33 pm #2592625Mel
Thanks, I added the CSS but now the top bar widget has disappeared (text line with contact details).
Also, I want the sticky version of the header to have a background color instead of being transparent. Or could I put the waves as Shape (or background) for the header instead of the content? Would that give me the wave in the sticky header also? The wave is a Shape on the Front Page and the other pages.
And I need the sticky header to have enough bottom space so the drop-down menu fits (in other words so the content is below the last item of the drop-down menu).
April 2, 2023 at 5:45 pm #2593738Fernando Customer Support
Hi Mel,
By default, just the navbar can be turned sticky through the Customizer. Having a merged header and making the top bar sticky along with the Header and changing its color is more complicated.
You’ll need Javascript which is out of our scope of support.
You could probably try creating a Hook Element with this code:
<script> const hwrap = document.getElementsByClassName("header-wrap"); window.addEventListener("scroll", function(){ if(window.scrollY==0){ hwrap[0].style.background = 'transparent'; } else { hwrap[0].style.background = 'white'; } }); </script>Hook it to
wp_footer.Set it to display for the Entire site.
Adding a shape would be more complicated.
April 2, 2023 at 5:55 pm #2593744Mel
Are there any plugins to make any element sticky? If yes, can you recommend any? Wouldn’t that be easier?
April 2, 2023 at 5:57 pm #2593746Mel
for example this plugin
Sticky Menu (or Anything!) on ScrollApril 2, 2023 at 8:29 pm #2593843Fernando Customer Support
I’m thinking one other possible easier way is to create a Block Element – Hook.
Hook it to
inside_navigation.Then, add the content of your Top Bar in this Block Element instead.
After doing this, let us know and we’ll check if there’s a simple CSS fix to move it to the right position.
If this doesn’t work, maybe we can consider a third party plugin then.
April 2, 2023 at 10:44 pm #2593947Mel
Hi, I haven’t yet done what you suggested but for some reason the CSS snippet mentioned by Ying earlier (/* Sticky Header */) works now, except the sticky header is transparent, I want it to have a background colour, I set it here before and it stopped working now (/* Sticky Navigation */)
/* Sticky Navigation */
nav#sticky-navigation {
background-color: #e7e0ca;
}
nav#sticky-navigation ul.sub-menu {
background-color: #e7e0ca;
}/* Sticky Header */
.header-wrap {
position: fixed;
top: 0;
}April 2, 2023 at 11:23 pm #2593991Fernando Customer Support
Yes. If you want that to have an opaque Background color on scroll, the code here is the solution: https://generatepress.com/forums/topic/sticky-header-18/#post-2593738
If you want an opaque color just for the top bar even when not scrolling then that could be done with CSS.
Let us know what you prefer.
April 2, 2023 at 11:52 pm #2594016Mel
This CSS code suggested by one of your support members earlier (at another forum topic I opened) worked before to make the complete sticky header opaque. Why has it stopped working now? I would prefer to just use CSS.
/* Sticky Navigation */
nav#sticky-navigation {
background-color: #e7e0ca;
}
nav#sticky-navigation ul.sub-menu {
background-color: #e7e0ca;
}April 3, 2023 at 1:00 am #2594104Fernando Customer Support
Did you disable the Sticky Header in Appearance > Customize > Layout > Sticky Navigation?
April 3, 2023 at 3:05 pm #2595373Mel
Yes, I disabled the Sticky Header in Appearance because I got the sticky header to work with the following CSS:
(I wanted the top bar Widget, the Kontakt details at the top included, which works now)/* Sticky Header */
.header-wrap {
position: fixed;
top: 0;
}This CSS worked previously to add background colour to the sticky header but stopped working now:
/* Sticky Navigation */
nav#sticky-navigation {
background-color: #e7e0ca;
}
nav#sticky-navigation ul.sub-menu {
background-color: #e7e0ca;
}So what I still need is to either add an opaque background colour or preferably the wave background (the wave is currently a Shape on the Front Page and the other pages) for the Sticky Header.
April 3, 2023 at 7:10 pm #2595507Fernando Customer Support
Well, you can either:
1. Choose to use the Sticky Navigation through the Customizer.
or
2. Use what you have now but use this code to change the color on scroll: https://generatepress.com/forums/topic/sticky-header-18/#post-2593738
April 6, 2023 at 3:30 am #2599232Mel
Hi, a friend managed to help me out with this one and he set a background image for the header and sticky header.
April 6, 2023 at 5:02 pm #2600284Fernando Customer Support
I see. Glad you resolved it!
-
AuthorPosts
- You must be logged in to reply to this topic.