Re: [csswg-drafts] [css-values-4] Switch advanced attr() to being var()-like (#4482)

There's a compatibility issue found via WPT [css/css-variables/variable-generated-content-dynamic-001.html](https://github.com/web-platform-tests/wpt/blob/master/css/css-variables/variable-generated-content-dynamic-001.html)

```
<style>
#parent { --x: attr(data-attr); }
#child::before { content: var(--x); }
</style>
<div id=parent><div id=child data-attr="foo"></div></div>
```

Before the spec change, we got a `::before` pseudo-element on `#child` with "foo".

Now the resolution of `attr()` is similar to `var()`. So we first compute `--x` on `#parent` by substituting `attr()`, and get the empty string. Then in `#child::before` we inherit `--x` from its parent, and get an empty `content`.

In other words, we got a behavioral change even when the declaration is valid.

---

Besides, could you clarify the substitution value for types `string` and `url` when the attribute is missing? The current spec says:
- For the fallback value: "...will be substituted instead of the attribute’s value if the attribute is missing or fails to parse as the specified type"
- For the `string` and `url` types: "No value triggers fallback"

I suppose there is always no substitution value when the attribute is missing? So that the behavior is different from when the attribute value is the empty string.

-- 
GitHub Notification of comment by xiaochengh
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4482#issuecomment-630566374 using your GitHub account

Received on Tuesday, 19 May 2020 04:06:48 UTC