[meta] Implement CSS Values 5 extensions to attr()
Categories
(Core :: CSS Parsing and Computation, enhancement, P3)
Tracking
()
People
(Reporter: zwol, Unassigned)
References
(Depends on 12 open bugs, Blocks 5 open bugs, )
Details
(4 keywords, Whiteboard: [DevRel:P2])
Reporter | ||
Updated•17 years ago
|
Updated•17 years ago
|
Comment 1•16 years ago
|
||
Comment hidden (advocacy) |
Updated•13 years ago
|
Updated•12 years ago
|
Comment hidden (me-too) |
Comment hidden (me-too) |
Comment hidden (me-too) |
Comment 7•11 years ago
|
||
notechnicalvalue |
Comment 8•10 years ago
|
||
Comment 9•10 years ago
|
||
Comment hidden (advocacy) |
Comment hidden (advocacy) |
Comment hidden (advocacy) |
Comment hidden (advocacy) |
Comment hidden (advocacy) |
Reporter | ||
Comment 15•10 years ago
|
||
notechnicalvalue |
Updated•10 years ago
|
Comment 16•10 years ago
|
||
Reporter | ||
Comment 17•10 years ago
|
||
notechnicalvalue |
Comment hidden (advocacy) |
Comment hidden (advocacy) |
Comment 21•10 years ago
|
||
Comment 22•10 years ago
|
||
Comment 23•10 years ago
|
||
Comment 24•9 years ago
|
||
Comment 25•9 years ago
|
||
Comment 26•9 years ago
|
||
Comment 27•9 years ago
|
||
Comment hidden (typo) |
Comment hidden (typo) |
Updated•9 years ago
|
Comment 30•9 years ago
|
||
Updated•9 years ago
|
Updated•9 years ago
|
Updated•8 years ago
|
Updated•8 years ago
|
Updated•8 years ago
|
Updated•8 years ago
|
Comment 31•8 years ago
|
||
Comment 32•7 years ago
|
||
Comment 33•7 years ago
|
||
Comment 34•7 years ago
|
||
Comment 35•7 years ago
|
||
Comment 36•7 years ago
|
||
Comment hidden (duplicate) |
Comment 38•7 years ago
|
||
Comment 39•7 years ago
|
||
Comment 40•7 years ago
|
||
Comment 41•7 years ago
|
||
Comment 42•7 years ago
|
||
Comment 43•7 years ago
|
||
Comment 44•7 years ago
|
||
Comment 45•7 years ago
|
||
Comment 46•7 years ago
|
||
Comment 47•7 years ago
|
||
Comment 48•6 years ago
|
||
Comment 49•6 years ago
|
||
This could make a huge difference for CSS layout, completely replacing grid systems…
[data-layout] {
grid-area: attr(data-layout custom-ident, auto / 1 / auto / -1);
}
Comment 50•5 years ago
|
||
(In reply to miriam from comment #49)
This could make a huge difference for CSS layout, completely replacing grid systems…
[data-layout] { grid-area: attr(data-layout custom-ident, auto / 1 / auto / -1); }
That wouldn't be valid, as far as I can tell, as auto / 1 / auto / -1
wouldn't parse as a custom-ident
.
Comment 51•5 years ago
|
||
I think that'd work if attr()
was defined more like env()
or var()
, except then you couldn't write things like attr(foo)px
.
Comment 52•5 years ago
|
||
I wouldn't expect attr(foo)px
to work anyway. The spec mentions attr(foo px)
as the syntax for converting the value to a specific unit.
But my idea may also fail because custom-ident
is not an actual option in the spec list <type-or-unit>
keywords. I was being very idealistic in my hope for this feature. Even a less dreamy grid-area: attr(data-area, main);
might not be supported by the current spec.
Comment 53•5 years ago
•
|
||
The spec link these days is this, I think:
https://drafts.csswg.org/css-values-4/
shoud summary change to refllect this?
Comment 54•5 years ago
|
||
Level 4 adds several mathematics capabilities over Level 3, including several functions beyond calc()
and definitions on methods for combining terms together when they affect the same property value. However, I don't see a substantial difference in substance between Level 3's and Level 4's definition of attr()
, just significantly more words to arrive at the same place. And Firefox isn't even there yet, though it's getting there.
Since this feature is part of Level 3, this bug blocks bug 741643, which is the metabug for implementing all of Level 3. If you feel strongly, you could file a new bug and say that it blocks bug 1531237, which is the metabug for implementing all of Level 4, but I wouldn't be surprised if it gets duped back to this one anyway.
Comment 55•5 years ago
|
||
(In reply to Andrew Cook from comment #54)
Level 4 adds several mathematics capabilities over Level 3,
...
Since this feature is part of Level 3, this bug blocks bug 741643, which is the metabug for implementing all of Level 3. If you feel strongly, ...
I don't feel strongly in any way, just noted that Chromium intends to ship this:
CSS Level 4 has made substantial revisions to attr() compared to Level 3 to ease the implementation. We'll follow CSS4.
https://groups.google.com/a/chromium.org/forum/m/#!topic/blink-dev/FGCgsKmylhw
Updated•2 years ago
|
Comment 57•2 years ago
|
||
For people wondering what the uses of this is, one good use (one that I would like to use for my forum software) would be to have javacscript-less user-definable colors for text.
In my case, users can use classic bbtext [color=#ff44aa]text here[/color] and such in their forum posts. However, a strict CSP and requiring full-feature fallback in the event there's no javascript available means that inline colors/sizes are right out- as a result I actually need to embed a CSS script with a calculated CSP nonce in the page with a generated ID for each custom color/size that appears in any post on the page. This is very heavy-weight (relatively speaking) to do on the backend for a forum software that's trying to be incredibly light-weight, and which could be easily solved with a single generic .user-color style and a data attribute on the generated HTML if this feature worked. It would also have the advantage of requiring no javascript (which would be the 'traditional' solution for this) which also reduces it's footprint, and browser requirements.
Comment 58•2 years ago
|
||
To note, there are unfiled blocking bugs for other/more types:
- ident
- number
- percentage
- length, angle, time, frequency (unimpl), flex
<dimension-unit>
Updated•2 years ago
|
Updated•2 years ago
|
Comment 59•2 years ago
|
||
Please note this was deferred until Level 5, so updated URL and blocking bugs.
Updated•2 years ago
|
Updated•2 years ago
|
Comment 60•2 years ago
|
||
Why this is important in my opinion:
-allows to set the calculations only in JS
-allows to set the markup only in HTML (attribute is updated from JS)
-allows to use data which updates with user's interaction, without setting the style from JS (or inline in HTML)
Obviously you could set a custom variable from JS but in doing so the final product is harder to read and maintain.
This CSS value, when not being taken as string only, allows for more flexibility while keeping things clear and organized.
As a string only it is useless, as a string value could only be used in pseudo-elements' content. There's not really much to gain from doing so.
Example:
I would like to track the mouse movement to set styles based on the X and Y position.
I can set an eventlistener which track the mouse movement in JS. This would get me X and Y numeric values.
Then the JS's values are set as the attributes' (X and Y) values in HTML.
Then these numeric values could be used in CSS thanks to attr()
This cannot be done currently as the default value is a string, and it cannot be set to a number, or a pixel value or anything else.
Comment 61•2 years ago
|
||
It would be a replacement for TailwindCSS.
For example if I wanted to put a dynamic size to a text with TailwindCSS it would be done this way:
<span class="text-base">Im not the king</span>.
But using attributes you could dispense with external JS libraries so that changing the text size could be done like this.
<span class="text-size" data-text-size="1.0"></span>
In the stylesheet there would be something like this:
.text-size {
font-size: attr(data-text-size, rem, 1);
}
For colors with TailwindCSS it would look something like this:
<span class="text-base text-blue-600">Im not the king</span>
Dispensing with the external JS library, we would do it like this:
<span class="text-size text-color" data-text-size="1.0" data-text-color="2563eb">Im not the king</span>
In the stylesheet there would be something like this:
.text-size {
font-size: attr(data-text-size, rem, 1);
color: attr(data-text-color, color, 000000);
}
Comment 62•1 year ago
|
||
(In reply to Oliver Medhurst [:canadahonk] from comment #58)
To note, there are unfiled blocking bugs for other/more types:
- ident
- number
- percentage
- length, angle, time, frequency (unimpl), flex
<dimension-unit>
I've created individual blocking bugs for them, now. Though I assume that the majority of types can be implemented together. So they might be merged once implementation begins.
Sebastian
Updated•1 month ago
|
Updated•27 days ago
|
Description
•