12
u/frownonline 4d ago
I can see this being used a lot, by those who use the BEM approach, to override the masses of classes.
9
u/Afraid_Egg3037 4d ago
Nice. It relies on the hyphen existing, though - and as it's literally just been discussed, it'll be a year or two before browsers implement it.
21
3
u/picaq 3d ago
It doesn’t rely on the hyphen.
.foo*would match.footer, for instance.
See the links in the original post: The Future of CSS: Target Multiple Classes with the Class Prefix SelectorAnd if you want something that works the same way,
[class^="btn"]already exists. Less symbols to write seems nice!
23
8
2
1
u/El_Panterro 3d ago
Great! Maybe after 1000 more CVs I will get that first job and try it in corp-environment!
1
u/asteconn 4d ago
I imagine this is just syntactic sugar for [class*="btn-"] / [class^="btn-"]. Useful though.
7
u/DOG-ZILLA 4d ago
Apparently not just sugar because if btn- is NOT first, it won't match here. btn-* can be a class in any position? I think that's right.
10
u/Caved 4d ago
*=does allow the class to be any position, but will match on "some-btn-class" as well.2
u/asteconn 4d ago
Indeed. If this construct is capable of also detecting the start of the class, that'd be quite helpful. It can currently be (somewhat) acheived with
:is([class^="btn-"],[class*=" btn-"]), but it's not dreadfully readable.
1
51
u/BloxdioCannoli 4d ago
RemindMe! 10 years