Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

more CSS <table> tricks 👇 stick the first row using <thead> so you don't lose context, and give it a margin so you don't lose the last row on scroll thead { position: sticky; top: var(--header-height); margin-bottom: 1lh; /* or whatever row height */ }

122,020 Aufrufe • vor 1 Jahr •via X (Twitter)

11 Kommentare

Profilbild von Brotzky
Brotzkyvor 1 Jahr

that margin bottom trick is slick

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 1 Jahr

it's a fun touch so it doesn't get trapped behind especially if you have a set line height for the tr, 1lh does it all 🙌 alternative "hack" is to absolutely position the last row with top: 100% 😈

Profilbild von Better Bedder
Better Beddervor 1 Jahr

The headband that wraps around your mattress. No need to tuck sheets under the mattress. Uses any bed sheets.

Profilbild von illyasreal von einzburp
illyasreal von einzburpvor 1 Jahr

@rejex_visions fancy tables

Profilbild von Alfon
Alfonvor 1 Jahr

Adding mb for the last row is genius! Incidentally, just seperate the last row into its own table maybe? HAHHAHA (what if the height is unknown)

Profilbild von (dm)ytro kondakov
(dm)ytro kondakovvor 1 Jahr

margin bottom is smart

Profilbild von Cyrus Zei
Cyrus Zeivor 1 Jahr

Never thought of that actually! Nice !! Thank you

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 1 Jahr

jus' a little trick so that final row doesn't get lost ✨

Profilbild von Даниил @grawl@mastodon.social
Даниил @[email protected]vor 1 Jahr

What if my rows is not fixed height

Profilbild von Speros Kokenes
Speros Kokenesvor 1 Jahr

What do you think about using CSS grid for tables instead? I've been doing it lately for data grids because it makes all kinds of CSS stuff like sticky headers seem a lot easier to implement (don't need tricks like the extra margin for example). Then add aria labels

Profilbild von jhey ▲🐻🎈
jhey ▲🐻🎈vor 1 Jahr

loses the semantics unless you add them all back the margin isn't there because it's a <table> fwiw but in any case, unless you really must, the native HTML table is strongly encouraged with the relevant role

Ähnliche Videos

CSS Tip! 🍬 You can create a CSS-only sticky CTA using position: sticky or scroll-driven animations 🤙 .cta { position: sticky; margin-top: 110vh; bottom: 2rem; /* 👈 Stick! */ } This is one way 👀 This first way relies on you setting a layout on the body and putting the CTA in a zero-space part of the layout body { display: grid; grid-template-columns: auto 0; } The children of the body are an element with your content and then the CTA. You could also use display:flex too. .content { flex: 1 0 100%; } .cta { place-self: end; } As you scroll the body, the CTA comes into view and sticks in position 🙌 That's one way. If you want to take it further and do something like flip between showing or not, maybe scale it up, or add some special easing, etc. an animation is another way 📜 First, change the styles for your CTA. Note the translate property that's powered by a custom property .cta { position: fixed; bottom: 2rem; right: 2rem; translate: 0 calc(20vh - (var(--show) * 20vh)); transition: translate 0.875s var(--elastic); } Next you need a custom property that you're going to animate @​property --show { inherits: true; initial-value: 0; syntax: ' '; } Lastly, you animate this value on the body. As the property value changes, the value will trickle down to the CTA @​supports (animation-timeline: scroll()) { body { animation: show-cta both steps(1); animation-timeline: scroll(root); animation-range: 0 10vh; } @​keyframes show-cta { to { --show: 1; } } } Using @​supports you can use this as a progressive enhancement. If scroll-driven animations are supported, use them. Otherwise fallback to using position: sticky 🤙 That's it! As always, any questions or requests, hit me up! 🙏 CodePen.IO link below! 👇

jhey ʕ•ᴥ•ʔ

133,020 Aufrufe • vor 2 Jahren

CSS Tip! 🐳 You can add little details like this scale down on scroll effect with scroll-driven animations and some sticky positioning 🤙 section { animation: scale-down; animation-timeline: view(); animation-range: exit; } @​keyframes scale-down { to { scale 0.8; } ] In this smaller example, you can lean into using the position to drive an animation that scales itself down as it leaves the viewport (Seen on the Apple Vision Pro site 🍏) The nice thing here is that if you don't have scroll-driven animations, the user still gets a good experience ✨ So how do you do it? There isn't much to it header { transform-origin: 50% 0%; animation: scale-down both ease-in; animation-timeline: view(); animation-range: exit; view-timeline: --header; } @​keyframes scale-down { to { scale: 0.8 0.8; } } That's it. The layout makes use of position: sticky so that the element stays in the shot whilst you scroll the page. As it leaves the page, it scales down inside the 🫶 The other smol animation here is fading the overlay on the video out 😎 Real easy. You may notice the view-timeline you defined above for the 👀 header { view-timeline: --header; } You have a pseudoelement on the text content of the header that lives inside a header > section::before { background: hsl(0 0% 0% / 0.75); opacity: 1; animation: fade both linear; animation-timeline: --header; animation-range: exit-crossing 0% exit 0%; } @​keyframes fade { to { opacity: 0; } } You use a slightly smaller range on this with exit-crossing to fade it out before you start the scale down animation 🤏 That's it! Thought this smaller example would be easier to grok for people 🙏 It's also covered with JavaScript if you really want it for your sites 🤙 CodePen.IO link below 👇

jhey ʕ•ᴥ•ʔ

146,270 Aufrufe • vor 2 Jahren