question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding padding between sticky element and top of viewport

See original GitHub issue

Right now my sticky elements always stick flush against the top of the viewport, but I’d like to give them a little bit of padding.

I did see the topOffset property, but as far as I can tell this only controls when the stickiness triggers, it still ends up sticking in the same place a top: 0.

I thought about using regular CSS padding, but that doesn’t work because it pushes the element down even when it isn’t sticking.

The result I’m looking for is basically how the sidebar behaves here: http://sidebar.io/ (scroll down), although for that project I used a different sticky position component.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
SachaGcommented, Oct 4, 2016

Thanks for the pointer! stickyStyle={{ top: <n> }} didn’t quite work because it interferes with the component’s logic for setting top, and caused the element to not stop being sticky properly.

But I was able to use padding-top to achieve the same thing. Also, it was actually topOffset: -n.

0reactions
jjh4698commented, Dec 7, 2016

Thank U! @SachaG very Helpful

Read more comments on GitHub >

github_iconTop Results From Across the Web

add space between sticky element and parent - Stack Overflow
Go with the "layout padding" option and simply set the sticky elements top to 0 - padding-top value set on the parent, top:...
Read more >
How to Get Sticky and Full-Bleed Elements to Play Well ...
To center the content, we are going to calculate left and right padding. The left padding is equal to the size of the...
Read more >
CSS Position Sticky - How It Really Works! - Elad Shechter
Sticky Item — is the element that we defined with the position: sticky styles. The element will float when the viewport position matches...
Read more >
scroll-padding-top - CSS: Cascading Style Sheets | MDN
The scroll-padding-top property defines offsets for the top of the optimal viewing region of the scrollport: the region used as the target ...
Read more >
position: sticky is Amazing - Mastery Games
Declare the element as sticky with position:sticky (plus any browser prefixes needed like position: -webkit-sticky ) · Specify an edge (top | right...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found