[csswg-drafts] [css-values] Function for (flattened) element content like `attr()` (#11483)

Crissov has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values] Function for (flattened) element content like `attr()` ==
Now that `attr()` has a type model that makes attributes more accessible to and usable in CSS, let’s consider whether there should be something very similar for element content: `element()`, `node()`, **`content()`** or `text()`. Since there is just one content, it would not need an attribute name as one of its arguments, but perhaps the nesting level to consider might be helpful, defaulting either to *top* or *all*.

I do not see any use cases for complex nested element content, which is why I think it should all be flattened to a space-normalized string, but I believe there would be some use cases for simple textual or (almost) numeric content. Take, for instance, cell content in data tables; it may be helpful – and within the domain of styling – to convert the data to a shorter representation more suitable for the available width (with MQ/CQ), e.g. custom text ellipsing, truncating floating point numbers, converting to scientific/engineering notation, scaling with SI prefixes, brief or expanded date notation, localizable relative time keywords, conversion to (image) symbols or emojis …

Some of this would require additional functions for string and number manipulation within CSS, but some would be possible today. 

Some text preprocessors, e.g. from Markdown to HTML+CSS, convert code spans that contain only a valid CSS color to a search representation of that color. 

~~~~ css
code::before {
  display: inline-block; width: 1em; height: 1em;
  background: content(type(<color>));
}
~~~~

Since most use cases I can think of would write the result back with the `content` property, this could as well be part of the [Content Module](https://drafts.csswg.org/css-content-3/#valdef-content-contents), which already has the related `contents` keyword.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11483 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Saturday, 11 January 2025 12:11:25 UTC