logoalt Hacker News

The Future of CSS: Target Multiple Classes with the Class Prefix Selector

13 pointsby cdrnsfyesterday at 10:51 PM8 commentsview on HN

Comments

jjcmyesterday at 11:43 PM

In their example, they list btn-* as the selector catch all for .btn-primary|secondary|danger. I can't help but think why not just do, .btn.primary for the class name, and just target .btn with the selector?

Don't get me wrong, I appreciate the convenience of this, but I do worry about selector slowdown with what will effectively turn into a regex at some point. I'm dubious that this is needed.

show 2 replies
CM30today at 12:35 AM

This is pretty neat. Definitely seems like something that'll make writing CSS for similar classes a lot more convenient, and another example of how modern CSS seems to be adding a ton of features to make front-end development a lot more efficient.

The increased level of power HTML, CSS and JavaScript have now is honestly kinda insane.

graypeggtoday at 12:24 AM

   *[class*=btn-] { ... }
I know you'd be matching on the class attribute instead of a single classname, but I feel like we'd see this much more out-in-the-wild if there was an apetite for this syntax feature right?

Like, the issue of `some-other-btn-primary` also matching the rule is pretty inconvenient, but definitely tolerable if people preferred writing style rules like this.

dymktoday at 12:12 AM

Personally, I don't think this is a great change to CSS. I prefer being able to grep for identifiers to see where they're used. Now you can't rely on that - maybe a rule is now covered by a prefix selector.

show 1 reply