惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Spread Privacy
Spread Privacy
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Forbes - Security
Forbes - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Last Watchdog
The Last Watchdog
SecWiki News
SecWiki News
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Secure Thoughts
WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
Security Latest
Security Latest
TaoSecurity Blog
TaoSecurity Blog
Cyberwarzone
Cyberwarzone
S
SegmentFault 最新的问题
Cloudbric
Cloudbric
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
H
Hacker News: Front Page
C
Cybersecurity and Infrastructure Security Agency CISA
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
AWS News Blog
AWS News Blog
AI
AI
G
GRAHAM CLULEY
IT之家
IT之家
P
Privacy & Cybersecurity Law Blog
L
Lohrmann on Cybersecurity
Last Week in AI
Last Week in AI
D
Docker
Recent Announcements
Recent Announcements
O
OpenAI News
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
Troy Hunt's Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic

Ben Frain

So, you want a React modal that uses the <dialog> element and transitions in AND out? Review: SoundPEATS Clip1 Open ear clip-on headphones VS Code – highlight just the active indent guide Review: MoErgo Go60, a split ergonomic and fully programmable keyboard Review: Kinesis mWave mechanical ergonomic and programmable keyboard iOS26 Safari theme-color/tab-tinting with fixed position elements is a mess New Book: Responsive Web Design with HTML5 and CSS, 5th Edition Use @supports with a proxy feature/value for features you can’t test for (@starting-style) First adventures in View Transitions Review: Benq Screenbar Pro and Halo lightbars. The kit you never knew you needed! Center items in a container, and make then left aligned when they overflow A single element CSS donut timer/countdown timer, that can sit on any background Review: Open Ear Headphones – Bose Open Ultra v Huawei FreeClip In search of the perfect autocomplete for CSS Managing multiple versions of node, without NVM or additional tools Review: Keychron Q14 Max Alice 96 Key mechanical keyboard NEW VIDEO COURSE: Responsive Web Design with HTML5 and CSS Is CSS Grid really slower than Flexbox? Review: Advantage360 Pro Signature Edition 2024 mechanical ergonomic keyboard More Keys or Fewer Keys for mechanical keyboards Yes! You can use position: sticky and overflow together Neovim – how to do project-wide find and replace? Review: Keyboardio Model 100, split, wooden, mechanical keyboard Struggling to learn SwiftUI How to create rounded gradient borders with any background in CSS How to get equal size icons in the cmp completion menu of Neovim with Kitty terminal Review: Dygma Defy, split, mechanical, programmable ergonomic keyboard What’s the best way to reset WAAPI chained animations? Using CSS @property inside shadowRoot (web components) workaround Dynamically create a ref for items when iterating over them in lit.dev templates Selecting and pausing running animations in Lit Web Components New Web APIs — a popover on top of a dialog element can’t be interacted with? Review: ZSA Voyager, split, mechanical keyboard Russel Brand, narcissism, and a sadly common pattern… When it comes to text editors, I feel like Goldilocks Simple settings for writing and converting markdown with Sublime Text Review: The ZSA Platform tenting kit for the Moonlander keyboard Logitech MX Master 3/3s scroll wheel fix Building a line graph with CSS clip-mask Review: Dell 6K 32″ Monitor U3224KBA I broke my keyboard! Swapping the key switches in the Kinesis Advantage360 Pro HUGE macOS Productivity boost: Set-up simple, keyboard only, instant App switching and arrangement Adding to $PATH for a central location for Neovim/NPM tools Neovim Power Tips: Volume 2 Review: MoErgo Glove80, split, wireless, columnar ergonomic keyboard with RGB Review: Kinesis Advantage 360 Pro — split ergo mechanical keyboard Review: Dactyl Manuform – an ergonomic, custom built mechanical keyboard How to animate along an SVG path at the same time the path animates? Getting the context of Web Components (lit)
Scroll indicators on tables with background colours using animation-timeline
Ben Frain · 2026-02-13 · via Ben Frain

Imagine a HTML table, with alternating rows with different background colours. The table content overflows the container on the right but on a mobile browser, with no obvious scrollbar, there is no affordance to know the table is overflowing.

I want to have a shadow/indicator on the side of the table that is overflowing the container.

Go to solutions that won't work

Many moons ago, Lea Verou popularised this approach: http://lea.verou.me/2012/04/background-attachment-local/

That general approach works great when your table does not have a background color. But mine does, so it doesn't work [insert Raspberry noise].

Then I remembered there was some way to do this with scroll() timelines. A web search or two past various web Illuminati (hi Adam!, hi Bramus) landed me at Dave's site.

Thank goodness Dave had written this as it got me a decent distance to the solution I ended up with.

However, the trouble I had with Dave's example as it was, was the same as the old skool one from years hence – it only worked if you have a table with no background colours in it. With background colors, it covered the inset shadows of the container.

"He conquers who endures." — Persius

So, having thought about it a little more, here is what I came up with…

The solution

I've got a table with a few columns, you can use whatever HTML table you like – mine shows the top 6 teams and their stats in the England Premier League.

Here is the result with the shadow technique added:

See the Pen
Untitled
by Ben Frain (@benfrain)
on CodePen.

Let's look at how this works. The table in a standard HTML table, nothing unusual there. It gets a wrapping element, such as a div, let's call the wrapping element 'TableWrapper'.

CSS Grid for layout

We set the TableWrapper layout with CSS Grid with a single row, and columns at either end for where we want our scroll indicators. For example:

.TableWrapper {
    display: grid;
    grid-auto-flow: column;
    grid-template: "leftindicator content rightindicator" auto / 30px max-content 30px;
    /* More styles */
}

Remember I said the table had background color? Let's add that to our table now.

table {
    tr:nth-child(even) {
        background-color: #444;
    }
}

We need our indicators to sit in the columns at either side of our grid. You could add extra elements inside the wrapper but I used ::before and ::after pseudo elements. I made them about 30px wide and gave them a linear gradient to make the shadow effect – one fades from dark to the transparent in one direction, and the other fades in another direction.

I ended up using grid to place the indicators, rather than something more conventional like absolute positioning, because this way, they will sit at either end of the table, but crucially, we can make them appear on top of the table and stuck to the edge of the scroll container with position: sticky. The higher z-index on the before/after ensures they appear above the table background.

Let's add the before/after elements into our TableWrapper. Here is the complete rule – note the grid-template to layout everything in the container. I removed the scroll-bar just to make the scroll indicators more needed (because a scrollbar is a pretty good scroll affordance already ;)).

.TableWrapper {
    display: grid;
    grid-auto-flow: column;
    grid-template: "leftindicator content rightindicator" auto / 30px max-content 30px;
    overflow-x: auto;
    scrollbar-width: none;

    &::before,
    &::after {
        content: "";
        height: 100%;
        width: 30px;
        display: block;
        z-index: 10;
        position: sticky;
        opacity: 0;
    }

    &::before {
        grid-area: leftindicator;
        left: 0;
        animation: show-indicator linear reverse;
        animation-timeline: scroll(nearest inline);
        background-image: linear-gradient(to right, #000, transparent);
    }

    &::after {
        grid-area: rightindicator;
        right: 0;
        animation: show-indicator linear;
        animation-timeline: scroll(nearest inline);
        background-image: linear-gradient(to left, #000, transparent);
    }
}

Modern CSS magic

There are a few things that only work due to modern CSS. If you want to know more about modern CSS, here is where I pimp my book, Responsive Web Design with HTML5 and CSS which covers all this stuff – find out more at https://rwd.education

First, I'm making both pseudo-elements position: sticky. The left/::before stuck to the left, the right/::after to the right.

Secondly I'm using animation-timeline, which is being set to scroll(nearest inline). So, if your brower doesn't support that, you won't see it.

In plain english, we have an animation, defined like any other with @keyframes:

@keyframes show-indicator {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

The animation is used on both before/after element and 'driven' by the scroll, with the ::before running the animation in reverse. We set the scroll() to be the nearest scrollable ancestor of the element we have set it on (because the before/after are effectively children of the TableWrapper). Super important — always put your animation-timeline after the animation shorthand otherwise the shorthand will wipe it out!

And that is it. Scroll indicators that show when either end of the scrollable content can be scrolled — even if that content has a background.

Postscript: I found this after the fact as well! Bunch more approaches too https://css-tricks.com/unleash-the-power-of-scroll-driven-animations/#aa-add-scroll-shadows-to-a-scroll-container