Skip to content

Instantly share code, notes, and snippets.

@marklchaves
Last active November 24, 2021 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marklchaves/31bbb2ad973e533a4863f9eacf0277c7 to your computer and use it in GitHub Desktop.
Save marklchaves/31bbb2ad973e533a4863f9eacf0277c7 to your computer and use it in GitHub Desktop.
How to Create a Floating Column Using CSS position: sticky in Avada

Usage

  1. Create your columns in Fustion Builder.
  2. Select the column you want to be sticky.
  3. Add floating-toc to the CSS Class setting for the column you selected.
  4. Add the following CSS to the page's CSS editor.
/** Add this to your page's CSS */
.floating-toc {
  position: sticky;
  top: 171px; /* Offset for the header. Adjust as needed. */
}

See the screengrabs in the comment below this gist.


References

How to add CSS to WordPress

Live demo on CodePen

CSS position on MDN


ko-fi

@marklchaves
Copy link
Author

marklchaves commented Jul 1, 2020

Screengrabs

Create your columns

avada-floating-column-demo-editor

Add your CSS class name to the sticky column

avada-floating-column-demo-col-css-class

Add your CSS for the sticky column

avada-floating-column-demo-page-css

@marklchaves
Copy link
Author

marklchaves commented Jul 1, 2020

Screencast Demo Running in Avada

Open the GIF and reload to view the demo.

avada-floating-column-demo

@cesabas
Copy link

cesabas commented Feb 12, 2021

not work for me!

@zoudano
Copy link

zoudano commented Feb 20, 2021

same it is not working for me, maybe because others elements are sticky in my page like the header ?

@marklchaves
Copy link
Author

Hi @cesabas and @zoudano,

I'd need to see your pages to see why this isn't working for you.

Cheers,

Mark

@zoudano
Copy link

zoudano commented Feb 22, 2021 via email

@marklchaves
Copy link
Author

Hi @zoudano,

I don't see a link to your page or any screen captures. Sorry if I missed them.

Thanks!

@zoudano
Copy link

zoudano commented Mar 1, 2021

oh its bizarrrr
voilà :
https://walkingwithenergy.today/eevents/
Capture d’écran 2021-03-01 à 09 31 02
Screenshot_2021-03-01 Edit Page ‹ Walking With Energy — WordPress(2)
Screenshot_2021-03-01 Edit Page ‹ Walking With Energy — WordPress

Thanks for your help

@twinklepandagre
Copy link

twinklepandagre commented Mar 5, 2021

I have also paste the same code in the css and its working for me but I'm getting problem with the text length. left column has 20-30 points but after pasting this code its showing only 10 points and im not able to scroll the content.

I want to make the column sticky but the content inside this column must be scrollable here is the link and some screenshots- https://patseerdvlpmnt.wpengine.com/quick-field-reference-manual/

github - 2
github - 3
github - 1

@marklchaves
Copy link
Author

marklchaves commented Mar 6, 2021

Hello @zoudano,

I thought it was the nested columns at first. My mistake. Your nested columns should be fine.

So, there's a parent div with id="boxed-wrapper" way high up in the DOM that breaks all elements with position: sticky on the page.

The hack to fix this is to unset the div's overflow style. Here's the JS that will do that and allow your sticky column to work.

(function () {
  let element = document.getElementById("boxed-wrapper");
  if (!element) return;
  element.style.overflow = 'unset'; /* To fix any position: sticky further down the DOM. */
})();

To do a quick test, copy/paste this code into your browser's console for that page. Then scroll up/down.

After testing, you can add this JS to your page's footer area using proper enqueue techniques in your child functions.php or the Insert Headers and Footers plugin.

Let me know how this goes.

@marklchaves
Copy link
Author

Hi @twinklepandagre,

The quick fix is to add max-height and overflow-y to your sticky element. The updated CSS for your page would look like this.

.floating-toc {
    position: sticky;
    top: 100px;
    overflow-y: scroll;
    max-height: 650px; /* Tweak this to your liking. */
}

@zoudano
Copy link

zoudano commented Mar 6, 2021 via email

@zoudano
Copy link

zoudano commented Mar 6, 2021

Hi Mark, too difficult for me ! I try few plugin to insert this code and nothing happen. I dont understand this morning, I try as you suggest first on my browser and It was working. Now I try again and nothing happen...

Can you make a screenshot of the eevent page showing it's working (the larger column (width) should stay fixed while we scroll down the longer column) So I will ask a developer to execute this script for me because I dont understand what I am doing

Thank a lot for your help

@marklchaves
Copy link
Author

Hello @zoudano,

I just published a complete how-to article complete with code and screen captures.

How to Unset CSS Overflow Using JavaScript when Sticky Elements Stop Working

Hopefully, this will help you. Let me know if I missed anything ;-)

Thanks!

@zoudano
Copy link

zoudano commented Mar 7, 2021 via email

@marklchaves
Copy link
Author

Hello @zoudano,

Excellent! I'm glad it's working now :-)

Sure, I'd like to learn more about your projects to see how I can help.

Can you please send me a message via the contact form on my website? The link to my website is on my profile @marklchaves.

Have a great weekend :-)

Mark

@Wordpresslover
Copy link

Hi, That sollution does not work with me @marklchaves Could you please take a look at my code? Here is the test page: https://rekinfinansow.pl/rekin-finansow-bije-rekordy-popularnosci/

@marklchaves
Copy link
Author

Hey @Wordpresslover,

Sorry for the delay. I just visited that page. I can see a sticky column on the right-hand side. It seems to work fine for me.

Let me know if you have any questions :-)

Thanks!

@jolution
Copy link

The class "position-sticky" with the information above worked as soon as I changed the parent div #boxed-wrapper from overflow:hidden to overflow:visible.

@marklchaves
Copy link
Author

Hey @jolution,

Excellent! Thanks for sharing that with everybody :-)

@Paeddy85
Copy link

Hello
I have the same problem. I installed the Avada theme and would like to add the sticky position to a column. I've tried all of the above solutions but none of them work.

The left graphic should stay when you scroll down.

You can see all the settings of the container and the column on the print screen.

What am I doing wrong?

Thank you very much for your feedback

Bild1

Container 1
Container 2
Container 3

Column 1
Column 2
Column 3

@Wordpresslover
Copy link

Wordpresslover commented Nov 23, 2021

@Paeddy85 no such built=in option in Avada. Avada has only sticky containers. For me Mark's css works:

  1. add css to you specific page or globally if you use it in many places.

/** Add this to your page's CSS /
.floating-toc {
position: sticky;
top: 171px; /
Offset for the header. Adjust as needed. */
}

  1. just add a class .floating-toc to your column and it should work.
  2. Report to Avada the need of a sticky column feature.

@Paeddy85
Copy link

@Wordpresslover Thanks for your answer. I've already tried this, but it doesn't work. What about the container settings are they right?

Bild1

Bild2

Angebot.Uberbauung.Bomus.-.Google.Chrome.2021-11-24.08-27-21.mp4

@Wordpresslover
Copy link

@Paeddy85 That's perrfectly okey wht you did. In your case an extra custom work is necessary though. If you want me to help you please contact me: https://companyromania.com/contact-us/

I will need a login to your test site to solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment