Adding padding between sticky element and top of viewport
See original GitHub issueRight 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:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the pointer!
stickyStyle={{ top: <n> }}
didn’t quite work because it interferes with the component’s logic for settingtop
, 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 actuallytopOffset: -n
.Thank U! @SachaG very Helpful