How to Make Custom Divi Header Fixed or Sticky

by | Jun 11, 2024 | Blogging, Tips & Tricks, Tutorials | 0 comments

Affiliate Disclosure: Some of the links in this post are affiliate links, which means we may earn a commission if you click through and make a purchase. For more details, please read our Affiliate Disclosure Policy.

Creating a fixed or sticky header in Divi has become significantly simpler with the introduction of the Position Options feature in the Divi 4.2 update. These new options are available in all Divi Builder modules, making it easier than ever to ensure your custom header remains visible as users scroll through your site. This is particularly useful for enhancing navigation and improving the overall user experience, as it allows visitors to access the menu and other key elements without having to scroll back to the top of the page.In this comprehensive tutorial, we’ll guide you through the entire process of using the Divi Theme Builder to create a custom header and set it to be fixed or sticky. Whether you’re a seasoned web designer or just starting out, this step-by-step guide will help you achieve a professional and functional header design that stands out.

Make Your Header Sticky with Divi’s Position Options

To make a section in your custom header fixed, start by opening the Section Settings for the specific section. Navigate to the Advanced tab, then to Positions. Under Position, select Fixed. Finally, set the location to Top Center. This will ensure that your header section stays at the top of the page as users scroll. 

With Divi's Position Options, making your header sticky is easy. This feature, introduced in the Divi 4.2 update, allows your header to stay fixed at the top of the page as users scroll.

Making the Header Sticky with Divi’s Position Options

Using CSS and jQuery to Fix Your Header

While the Position Options in Divi simplify creating a fixed header, they don’t allow us to dynamically change the header styles as the user scrolls, a feature found in the default Divi header.To achieve this dynamic styling based on scroll behavior, we’ll need to implement a jQuery solution. This approach enables us to customize how the header looks and behaves after a user scrolls down the page.

Read More: Basics of Divi Responsive Design

Here’s how to set it up:

  1. Open the Section Settings for the section you want to make sticky.
  2. Navigate to Section Settings > Advanced > Custom CSS ID & Classes.
  3. In the CSS ID field, enter dc-main-header.
In the Divi Builder, open the settings for the section you want to modify. Under the "Advanced" tab, find the "CSS ID & Classes" option, then enter your desired CSS ID in the "CSS ID" field.

Assigning a CSS id to the Divi Section

Next, navigate to your WordPress Dashboard and click on “Divi.” From there, go to “Theme Options” and then select “Integration.” You’ll find an option to add code to the <head> section of your blog. Paste the following code into that section. This code will integrate the necessary functionality for your customizations.

<script>
jQuery(function($){
$(function() {
  
    var header = $("#dc-main-header");
    $(window).scroll(function() {
        var scroll = $(window).scrollTop();
 
        if (scroll >= 0) {
            header.addClass("et-fixed-header");
        } else {
            header.removeClass("et-fixed-header");
        }
    });
});
});  
</script>

This code dynamically adds the CSS Class et-fixed-header to the section when you scroll down, and removes it when the header returns to the top. However, merely adding the class doesn’t make the section fixed on scroll. To achieve a fixed header effect, you need to take an additional step. Navigate to your WordPress Dashboard, go to Divi, then Theme Options, and finally to Custom CSS. Insert the following CSS code to ensure the section remains fixed as users scroll:

#main-header.et-fixed-header {
    position: fixed;
}

The CSS code dynamically fixes the header, allowing us to easily adjust styles for the fixed menu using the et-fixed-header CSS class.  You can also use the class “et-fixed-header” to target other elements within the section and modify their styles as you scroll. This allows you to customize the appearance and behavior of various elements along with your fixed header.

Read More: Add auto updating footer copyright in Divi without coding

Final Thoughts:

Creating a fixed or sticky header using Divi opens up new possibilities for improving user interaction and navigation on your website. The introduction of Position Options in Divi 4.2 has streamlined the process, making it accessible even to those without extensive coding knowledge. By implementing these features, you ensure that important navigation elements like menus remain readily accessible to visitors as they explore your content.

While Divi’s built-in tools provide a solid foundation for making headers sticky, integrating CSS and jQuery allows for more dynamic customization. This approach not only fixes the header position but also enables changes in appearance and behavior based on user scroll actions. Whether you opt for the straightforward Position Options or delve into custom scripting, the result is a website that not only looks professional but also enhances usability.

In conclusion, mastering the art of creating fixed or sticky headers with Divi empowers you to deliver a seamless browsing experience that keeps visitors engaged and satisfied. Whether you’re enhancing an existing design or starting fresh, these techniques ensure your header remains a functional and stylish focal point throughout the user journey.

Read More: Animate Your Web Page Using Divi Scroll Effects

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Stay ahead with the Latest WordPress Insights

Subscribe for tips, updates, and exclusive tools to elevate your website game.

Newsletter

No spam ever. Only Divi related updates. You need this.

Pin It on Pinterest

Shares