Skip to content
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

[css-values] Key-Value and Index Maps for attr() #4484

Open
Crissov opened this issue Nov 5, 2019 · 1 comment
Open

[css-values] Key-Value and Index Maps for attr() #4484

Crissov opened this issue Nov 5, 2019 · 1 comment

Comments

@Crissov
Copy link
Contributor

Crissov commented Nov 5, 2019

Note: […] The attr() expression cannot return everything, […]. This is intentional, as the intent of the attr() expression is not to make it possible to describe a presentational language’s formatting using CSS, but to enable CSS to take semantic data into account.

To achieve this goal, I think attr() would benefit from a way to map attribute values to CSS values.

  • Key-value pairs: attr(party map("Dem" blue, "Rep" red, "Grn" green) color, gray)
  • Numeric index:
    • 1-based: attr(rank map(gold, silver, orange) color, gray)
    • 0-based: attr(rank map(black, gold, silver, orange) color, gray)
    • explicit: attr(rank map(1 gold, 2 silver, 3 orange) color, gray)
  • mixed: attr(rank map(gold, silver, orange, "DQ" red) color, gray)

Similar results can already be achieved with attribute selectors, though:

  • [party] {color: gray} [party="Dem"] {color: blue} [party="Rep"] {color: red} [party="Grn"] {color: green},
  • [rank] {color: gray} [rank=1] {color: gold} [rank=2] {color: silver} [rank=3] {color: orange} [rank=NQ] {color: red}
@Crissov
Copy link
Contributor Author

Crissov commented Jan 21, 2025

Rediscovering this suggestion of mine, I think with recent changes and additions to CSS, it probably makes more sense to do such mappings in a way that is also usable with var() etc., i.e. move the attr() inside the map():
map(attr(party <string>), "Dem" blue, "Rep" red, "Grn" green, gray) etc.

I thought @LeaVerou had raised a similar issue, but neither #9992 nor #11543 seems to be it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants