Skip to content

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

Closed
@Crissov

Description

@Crissov

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}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions