Hacker News new | ask | show | jobs
by degamad 300 days ago
But in any context in which the attr() function is used, the type information is inherent, right?

    min-width: attr(foo) /* implicitly requires type to be length */
    color: attr(bar)     /* implicitly requires type to be color */
Unless you wanted to use a shorthand property like border, but restrict the attribute to only one part of it?

    border: 1px attr(bdrcolor type(<color>)) /* needs explicit type to prevent specifying border-style  */
But that would be easier and cleaner to specify separately?

    border-width: 1px 
    border-color: attr(bdrcolor)  /* implicitly requires type to be color */
In what scenarios does adding the explicit type information help, rather than having the parser infer the type of the attr() based on the context of the call?
1 comments

Yeah, my thinking exactly.

CSS variables are another thing to consider perhaps. You can specify their type explicitly as well (albeit using a more verbose syntax):

  @property --logo-color {
    syntax: "<color>";
    inherits: false;
    initial-value: attr(logo-color);
  }