Loading video...

Video Failed to Load

Go Home

Future CSS Tip! ๐Ÿ”ฎ Anchor Positioning lets you anchor elements to others with CSS alone ๐Ÿ‘ It can also work out positioning if an element gets clipped by a container, window, etc. Think "Common floating UI uses with no JS" ๐Ÿคฏ .el { bottom: anchor(--link top); } Just CSS ๐Ÿ‘‡

160,649 views โ€ข 3 years ago โ€ขvia X (Twitter)

10 Comments

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

If you want to see this demo in action, here's the @CodePen link! ๐Ÿค™ You'll need to be in Chrome Canary with the "Experimental Web Platform Features" flag enabled โ›ณ๏ธ This one anchors Popovers using the Popover API ๐Ÿ˜Ž

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

And here's an article I put together all about Anchor Positioning that looks into some of the main parts of this CSS API ๐Ÿ‘€

Andreas Eracleous's profile picture
Andreas Eracleous3 years ago

This is great! tip! thanks you for sharing

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ3 years ago

It'll be pretty cool when/if it lands in other browsers! ๐Ÿ’ฏ

blah's profile picture
blah3 years ago

Unrelated question but when is it the right time to implement these new css features? Browser support can widely vary and many systems will still run old browser version so what's the recommended way to go about this?

AellL's profile picture
AellL3 years ago

@SaveToNotion #thread #css

Shripal Soni's profile picture
Shripal Soni3 years ago

Wow! This will be really very helpful ๐Ÿคฉ

Marina Luna's profile picture
Marina Luna3 years ago

๐Ÿคฏ!

Erik Rasmussen ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ‡ช๐Ÿ‡ธ's profile picture
Erik Rasmussen ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ‡ช๐Ÿ‡ธ3 years ago

Whoaโ€ฆ

Joshua Riley's profile picture
Joshua Riley2 years ago

A @tailwindcss version of this would be amazing

Related Videos

CSS in 2024 ๐Ÿคฏ You can create a range slider with updating value tooltip and color changing track without using any JavaScript ๐Ÿคฏ ::-webkit-slider-thumb{ view-timeline: --thumb inline; } Scroll animation on the slider thumb that animates a number between the "min" and "max" of the range ๐Ÿ˜… @โ€‹property --value { syntax: ' '; } @โ€‹keyframes sync { to { --value: 100; }} Tie that up to the contain animation-range โšก๏ธ .control { animation: sync both linear reverse; animation-timeline: --thumb; animation-range: contain; } Hoist the view timeline so the tooltip can use the value too! :root { timeline-scope: --thumb; } Then use it in the counter which goes in the tooltip ๐Ÿ˜‡ .tooltip { counter-reset: val var(--value); } .tooltip::after { content: counter(val); } Then the accent color is based on the value too ๐ŸŽจ [type=range] { accent-color: hsl(var(--value) 90% 65%); } The magic from the quoted post is using anchor positioning on the range thumb to position that tooltip ๐Ÿ‘ Never thought of that when working on the spec for this API. This API lets you tether elements to other elements. Using the pseudo is a clever move! ::-webkit-slider-thumb { anchor-name: --thumb; } .tooltip { position: absolute; anchor-default: --thumb; left: anchor(50%); bottom: calc(anchor(top) + 25%); } The last piece is the little bounce transition... OK. I used a line or two of JavaScript for that ๐Ÿ™๐Ÿ˜ฌ const updateDelta = ({ movementX }) => { documentโ€‹.documentElementโ€‹.style.setProperty('--delta-x', movementX) } document.body.addEventListener('pointermove', updateDelta) But only so you can pass the movement delta to CSS and then reset the position with linear() to get that bouncy transition ๐Ÿ˜Ž .hint { rotate: calc(clamp(-60, var(--delta-x) * -1, 60) * 1deg); transition: rotate 1s linear( 0, 0.2178 2.1%, 1.1144 8.49%, ... ); } Should probably do a video on this one. Lots of little tricks to break down with it for sure! ๐Ÿ’ฏ As always, any questions, let me know! Also, this one only works in Chrome Canary with the Experimental Web Platform Features flag enabled โœ… This one almost feels like rocket science ha ๐Ÿš€ CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

251,867 views โ€ข 2 years ago

CSS Tip! โœจ It's 2024 and you have a new way to make animated borders ๐Ÿš€ .glow::after { offset-path: rect(0 100% 100% 0 round var(--radius)); animation: loop; } @โ€‹keyframes loop { to { offset-distance: 100%; }} Using the offset-* properties you can animate elements along the perimeter of others ๐Ÿ˜ The rect() value gained support in Safari 17.2 ๐Ÿ™Œ To start, you create an element and put it inside your main element. For example, you put a span inside the button ๐Ÿค™ Click me! Make the element fill its parent with absolute positioning and inset [data-glow] { position: absolute; inset: 0; } Now the good part, you use a pseudoelement on that element and define an offset-path [data-glow]::after { content: ""; offset-path: rect(0 auto auto 0 round var(--radius)); animation: loop 2.6s infinite linear; } With the rect value, you are saying the path fills the parent container: top: 0 right: auto || 100% bottom: auto || 100% left: 0 Then you can use round to make sure the path uses the same radius as whatever the parent has The @โ€‹keyframes animation merely animates the offset-distance of that pseudoelement to 100% @โ€‹keyframes loop { to { offset-distance: 100%; }} You can see this more clearly in the video ๐Ÿซถ The offset-* properties also include an offset-anchor property. This allows you to dictate which point of the element follows the path. For example: anchor-offset: 100% 50%; This means that the "right, center" of the element will follow the perimeter of the parent element ๐Ÿค™ Lastly, the visuals ๐ŸŽจ For color, you can use a gradient such as a linear gradient to fill the pseudo-element. [data-glow]::after { background: radial-gradient( circle at right, hsl(320 90% 100%), transparent 50% ); } Then clip away everything so you only have the border and can still have translucent backgrounds, etc. Use a mask with mask-composite โœจ A little transparent border trick: [data-glow] { border: 2px solid transparent; mask: linear-gradient(transparent, transparent), linear-gradient(white, white); mask-clip: padding-box, border-box; mask-composite: intersect; } Bit of a long one. Hope you find it useful ๐Ÿ™ CodePen.IO link below ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

283,498 views โ€ข 2 years ago