Floating a Q2W3 Fixed Widget in Divi

Written by Dan Mossop

The Q2W3 Fixed Widget (Sticky Widget) plugin allows you to mark individual widgets as sticky, meaning that when you scroll up the page they will stay in position on the screen, rather than scrolling out of sight with the rest of the content. A good use for the plugin is to create "floating" widgets which hover above the page content, for instance to have social share buttons visible at all times.

Unfortunately, in some themes (including the Divi Theme), setting float:left on the sticky widget will not move it into position on the sidebar. This is because the theme is made up of a number of other left-floated elements. These elements block the widget, effectively keeping it in position.

To work around this, we can use a bit of JavaScript (jQuery, actually) to move the widget into a new position within page. By placing it before the other components, we'll prevent them from blocking the widget's floating. Here is the jQuery to move a widget with id "text-4" to the start of the Divi Theme page content:

jQuery("#et-main-area").prepend(jQuery("#text-4"));

This frees the widget, but doesn't fully achieve the floating effect we want. So we need to add some CSS to make it look right:

#text-4 { width:200px !important; z-index:100; position:fixed; }
#text-4_clone { width:1;height:1; }

The first line sets the widget width and fixes it above the other content. The second line is used to prevent a hidden object created by the plugin from breaking the page layout. Note that the id selector in the second row is made up of the widget id followed by "_clone".

Now the widget should float on the left of the page. We may still need to set the top margin in the Q2W3 Fixed Widget settings to make sure the widget is not covered up by the header bar.

Transform Your Divi Site with WP Magic CTAs

Enhance your Divi site by creating dynamic, AI-driven call-to-actions with WP Magic CTAs. This plugin allows you to effortlessly increase post engagement and conversions by integrating highly-targeted CTAs directly into your WordPress posts using shortcodes or Divi's dynamic content. Perfect for making your posts more interactive and driving user action.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

2 Comments

  1. where do I need to put this code?

    Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.

Latest From Divi Booster

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Fix Divi Text Module "Regular" Font Weight Not Working

Are you encountering an issue where the font weights in Divi's Text Module don't seem to apply as expected? In particular, you might find that when you set the text module's body text font weight to "Regular", your font is actually assigned a weight of 500 instead of...

Make the Divi Gallery Module Swipeable

The Divi Gallery Module comes with a slider mode that lets you display images in a slider with clickable left/right arrows to scroll through the images. For mobile / touchscreen users, you can improve the user experience by allowing your user to swipe to navigate to...

How to Use Divi Dynamic Content in Woo Modules Product Selector

Divi's Dynamic Content is a powerful feature that lets you populate your Divi modules and theme builder templates with data pulled in various sources, such as custom fields. This allows for efficient organization and maintenance of your sites.Unfortunately, Divi's...

Random Divi Posts