Every demo uses plain CSS and a few lines of vanilla JavaScript to switch classes. Open your browser's dev tools on any box to see the computed styles.
The frame below is its own small page, so fixed and sticky behave as they would on a real site. Scroll inside it.
The orange box has position: absolute; top: 0; right: 0. It goes to the corner of its nearest positioned ancestor. With none, it uses the page itself and lands in the top-right corner of this document.
The box is a child of .parent in the HTML in every mode. Only the ancestors' position changes.
.box { position: absolute; top: 0; right: 0; }
.parent { position: relative; } /* the box's containing block */
Scroll the box. The dark header has position: sticky; top: 0 in every case except "No top value".
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
.header { position: sticky; top: 0; }
.header { position: sticky; } /* no top: it behaves like relative */
.wrapper { overflow: hidden; } /* the wrapper becomes the sticky's scroll container, and it never scrolls */
.header { position: sticky; top: 0; }
<div class="holder"><div class="header">…</div></div> /* sticky can't leave its parent. The holder is only as tall as the header, so there's no room to stick */
.wrapper { overflow: clip; } /* clips like hidden, but isn't a scroll container */
.header { position: sticky; top: 0; }
The "Chat" button has position: fixed; right: 16px; bottom: 16px and sits inside the card in the HTML. On a plain card it goes to the corner of your browser window. If the card has any of the other properties, the card becomes its containing block and the button gets stuck inside it.
.chat { position: fixed; right: 16px; bottom: 16px; }
.card { transform: translateZ(0); } /* any transform, filter, will-change: transform or contain: paint traps it */
The menu has z-index: 9999. Card B has position: relative; z-index: 1. Whether the menu covers card B depends on card A, not on the menu.
.menu { position: absolute; z-index: 9999; } /* card A makes no stacking context: 9999 competes with card B's 1 */
.card-a { position: relative; z-index: 1; } /* new stacking context. Tie with card B, and B comes later in the HTML */
.card-a { opacity: .99; } /* also a stacking context, painted at level 0, below card B's 1 */
.card-a { transform: translateZ(0); } /* same: stacking context at level 0 */
.card-a { position: relative; z-index: 2; } /* raise the context, not the menu */
Scroll this box.
The header stays at the top of it.
It needs top: 0.
And no overflow: hidden between it and the scroller.
More text.
More text.
End.
/* Badge on a card */
.card { position: relative; }
.badge { position: absolute; top: -10px; right: -10px; }
/* Tooltip */
.tip { position: relative; }
.tip [role=tooltip] { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); }
/* Sticky header */
header { position: sticky; top: 0; }
/* Modal overlay */
.overlay { position: fixed; inset: 0; }
.modal { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }