-
Notifications
You must be signed in to change notification settings - Fork 711
[css-selectors] add numeric comparisons on attribute values #5890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There is already #354, which has various proposals like this. But not sure if it's better to split them among multiple subissues, like this one. |
Thanks @Loirooriol - i don't know why i didn't find 354 when i was searching. On the other hand maybe considering numeric values by themselves might make them easier to get adopted. |
(Cross-post from #354) To numerically compare attribute values today, authors can work around this by:
I’ve detailed this nasty and cumbersome hack back in the day over at https://www.bram.us/2016/10/13/css-attribute-value-less-than-greater-than-equals-selectors/. |
Can a flag like
|
It's not much clear how |
I assume it wouldn't. Using it would be a syntax error.
Right, inequalities are vital for this use-case, so this wouldn't really help. A flag doesn't really add anything anyway - attribute selectors currently require the value to be an ident or a string, so numbers are invalid. Thus |
Can we have numeric comparisons?
e.g.
[data-balance<0] { color: red; } (common in accounting/finance, along with putting ( ) around the value)
[data-eyes>7.9] { color: black; background-colour: yellow } /* spider! */
with < <= > >=
Noting that testing for equality is string equality so testing 06=6 fails, an alternative design might be to calc() to fetch an attribute value, and to be allowed in selectors, but that's more complex.
Maybe a new section inhttps://drafts.csswg.org/selectors/#attribute-selectors for Numeric Attribute Values?
The text was updated successfully, but these errors were encountered: