Sticky headers can be effective for keeping your menu and other important CTAs accessible for users. But sometimes sticky headers can become distracting, especially for large headers on smaller screen sizes. Usually, we resort to shrinking the header and/or hiding elements in the sticky state to create more space for content. However, creating a toggle tab for those sticky headers could be a great alternative. Including a small toggle tab under the sticky header gives users the option to hide/show that sticky header whenever they want. In this tutorial, we are going to show you how to create a toggle tab for a sticky header in Divi.
Let’s get started!
Here is a quick look at the Sticky Header Toggle Tab we’ll build in this tutorial. Notice how the toggle tab becomes visible once the user scrolls beyond the height of the header. Then the user can toggle the sticky header by clicking the tab. Once the user scrolls back to the top of the page, the header is made visible and the tab is hidden.
And here is a codepen demonstrating this same concept.
Download the Toggle Tab for Sticky Header Template for FREE
To lay your hands on the designs from this tutorial, you will first need to download it using the button below. To gain access to the download you will need to subscribe to our Divi Daily email list by using the form below. As a new subscriber, you will receive even more Divi goodness and a free Divi Layout pack every Monday! If you’re already on the list, simply enter your email address below and click download. You will not be “resubscribed” or receive extra emails.
Join the Divi Newsletter and we will email you a copy of the ultimate Divi Landing Page Layout Pack, plus tons of other amazing and free Divi resources, tips and tricks. Follow along and you will be a Divi master in no time. If you are already subscribed simply type in your email address below and click download to access the layout pack.
You have successfully subscribed. Please check your email address to confirm your subscription and get access to free weekly Divi layout packs!
To import the template to your Divi Library, do the following:
Once done, the template will be available in the Divi Theme Builder.
From there, you can open the template settings and assign the template to any or all pages of your website to test out the results. Or you can click open the header template editor to edit the template layout.
Let’s get to the tutorial, shall we?
Part 1: Uploading the Premade Header Template to the Divi Theme Builder
To speed up the building process for this tutorial, we are going to use a premade header which is free to download from our blog.
Download the Template
To get the premade header template, go to the post featuring our FREE Header and Footer Template for Divi’s Interpreter Layout Pack.
Then enter your email address inside email option. Once done, you will see the “Download the Files” button. Click on the button to download the file.
Once the file is downloaded, unzip the JSON file.
Import the Template
Next, navigate to Divi > Theme Builder. And click the portability icon at the top right of the page.
Select the Import tab, choose the JSON file you just unzipped, uncheck the options and click the import button.
Next, select the option “Import them as static layouts…” and click the Import button again.
Open the Header Template Editor
Once the template has been loaded to the theme builder, delete the footer of the template and click save changes. Then click the edit icon to edit the custom header of the template.
Open Layers Modal and Delete Existing Code Module
In the header layout editor, open the settings menu at the bottom of the page, and click the layers view icon to open the layers modal. This will help us access our Divi elements easier going forward.
In the layers modal, click the Open/Close All toggle so you can see all the Divi Elements. In the second row of the section, delete the code module. We won’t need this custom code for this tutorial.
Part 2: Creating a The Sticky Header with Toggle Tab in Divi
The Section Settings
For this header, we are going to make the entire section sticky so that the header will stick to the top of the page when scrolling. We will also give the section a custom CSS Class to target later on with our custom code.
Open the section settings and update the following:
Creating the Toggle Tab with a Blurb Module
Next, we are going to create our toggle tab using a blurb module.
To do this, add a new blurb module at the very bottom of the second row under the menu module.
Then open the blurb settings and update the content as follows:
Under the design tab, update the following:
NOTE: With the transform translate Y set to 100%, the icon will move down exactly 100% of the icon’s height (45px).
Under the Advanced tab, update the following:
Now that the blurb has an absolute position (with the transform translate Y 100%), the blurb (toggle tab) will sit right below the entire header section. This is important so that the toggle tab will remain visible/clickable when we show/hide the header when clicking the toggle tab.
Add the Custom Code
To add the functionality we need for this sticky header toggle, we will need to add some custom CSS and JQuery.
To do this we will add a new code module below the blurb module.
Inside the code content box, paste the following CSS making sure to wrap the code in the necessary style tags.
Under the ending script tag surrounding the custom CSS, paste the following JQuery making sure to wrap the code in the necessary script tags.
To view the final result, you will need to assign the template with the new header to a page or all pages of your website.
To do this, save the layout and exit the header template editor.
Then open the template settings (the gear icon) for the template with the new sticky toggle tab header. Under the Use On tab, select All Pages and click the Save button.
IMPORTANT: This will show the header on all pages of your website. So make sure you are using a staging site and not your live website.
Now, open any page on your website to see the result.
Here is a preview of what it will look like on desktop, tablet, and phone.
In this tutorial, we showed you how to create a toggle tab for a sticky header. This can be a helpful solution both for developers that want to keep important sticky header content accessible to users and also for users that want to hide or show that header whenever they want. Hopefully, this will come in handy for a future project!
I look forward to hearing from you in the comments.
This content was originally published here.