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

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
O
OpenAI News
AI
AI
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
TaoSecurity Blog
TaoSecurity Blog
The Cloudflare Blog
V
Visual Studio Blog
Forbes - Security
Forbes - Security
Apple Machine Learning Research
Apple Machine Learning Research
Spread Privacy
Spread Privacy
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
The Last Watchdog
The Last Watchdog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
Cisco Talos Blog
Cisco Talos Blog
Security Latest
Security Latest
量子位
W
WeLiveSecurity
V
V2EX
L
Lohrmann on Cybersecurity
S
Security @ Cisco Blogs
小众软件
小众软件
The Hacker News
The Hacker News
阮一峰的网络日志
阮一峰的网络日志
H
Hacker News: Front Page
博客园 - 聂微东
T
Troy Hunt's Blog
S
Schneier on Security
有赞技术团队
有赞技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
Webroot Blog
Webroot Blog
P
Privacy International News Feed
Jina AI
Jina AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

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