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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
美团技术团队
量子位
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
小众软件
小众软件
博客园 - 司徒正美
罗磊的独立博客
云风的 BLOG
云风的 BLOG
B
Blog RSS Feed
博客园 - 聂微东

remy sharp's b:log

Redesign '26 AI for alt text? text-decoration-thickness discrepancies Are We at War with AI Agent “Civilizations”? Before you buy an LTE Pixel Watch (for your teen) I Who Have Never Known Men 16 for Tia The Talented Mr Ripley (Ripley, #1) Dark mode toggles: two states are enough I'm not done using AI On AI Coding and Its Discontents Three Men in a Boat Not All Screen Reader Users Are Blind Progressive Enhancement inside of JavaScript A Firefox-only minimap Pokémon Emerald Human Software Rescued Pokémon Yellow when-do web component 'VPNs are lawful technical tools,' says EU Court in landmark copyright ruling Image to text The Air Raid Book Club The infinite scroll may become endangered if controversial Calif. law passes In defense of polyfills • Lea Verou This was the first commit via an LLM to git AI Content Is Everywhere on Social Media, Especially LinkedIn Web Platform Wishlist on Vale.Rocks querySelector immediate children with :scope Fundamentally Why we moved our Bluesky data to Eurosky
Wildcards In CSS
Remy Sharp · 2026-07-11 · via remy sharp's b:log

Just a brainfart here, but it's odd that even though we have wildcard selectors throughout CSS, and even partial selectors (I'll explain in a bit) we don't have partial wildcard selectors on top level elements.

I'm not talking about the "star" rule, but what I imagine would be a wildcard on elements selector.

Existing methods

If I want to select and style all the .btn-* classes using attribute selector, I'd do this:

[class^="btn-" i] {}

This selector says: find all the elements with the class attribute that starts with "btn-" - case insensitive.

It's rather brittle, because it requires that the HTML class attribute starts exactly with btn-. Though it works, it does tie the HTML closely to the CSS - which I'd argue you'd want to be very sure you need to do.

But it is possible.

Equally, and a lot more robust, is the wildcard that says "anywhere in the attribute", so:

[class*="btn"] {}

It's fine, but it's a bit sledgehammery. However, if you want to do the same thing for a web component, for instance, you can't.

If I want to target all the rem-xxx custom components using rem-* { … }, I can't.

Obviously I'm not the first to think of this, and of course the venerable Lea Verou has thought about this and filed the issue over two years ago, though there doesn't seem to be much interest in supporting it.

The reason it crossed my mind is that I was thinking about how you would initialise web components on a page, and currently it requires searching every single element in the DOM, rather than targetting to the nodes you want ahead of time.

From this MDN article they included a code snippet that (I thought) was a clever way to initialise the components:

for (const element of document.querySelectorAll("*")) {
  const tag = element.tagName.toLowerCase();
  if (tag.startsWith("mdn-")) {
    const component = tag.replace("mdn-", "");
    import(`../components/${component}/element.js`);
  }
}

But really, it should be:

for (const element of document.querySelectorAll("mdn-*")) {
  const component = element.tagName.toLowerCase().replace("mdn-", "");
  import(`../components/${component}/element.js`);
}

This feels like a relatively cheap change to add support for wildcards, and gives the querySelectorAll a nice little boost, along with the benefits Lea already outlined in the github issue she raised.

Would it be valid?

I swear I found the documentation that read that the * asterisk was reserved for the universal selector (i.e. match all things), but I can't find it any more.

However, the from my memory, the parser only allows an asterisk after a space, to indicate it's a universal selector, so foo* or foo-* would not match in the parser.

Equally, it's allowed in the attribute selector, but only when followed by =, but attribute selector already has wildcard support. But maybe this would be extended to cover "glob" like support, so I could do .foo*bar to match .foo-dont-do-it-bar. Again, the current parser doesn't allow for this, so that means it's available for use.

Published under #code. Edit this post