-
Notifications
You must be signed in to change notification settings - Fork 699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-background-4] add background-layers property to set everything but background-color #8726
Comments
+1 We could then define |
Note we can think about |
I don't have a strong opinion on this, but it sounds reasonable, and the proposal itself seems right.
Right, name-wise we almost never do plurals, so it would be
Yeah, it would be a separate shorthand, unrelated to the |
As there's just positive feedback for this suggestion, so far, let's get a resolution on whether to add it. The proposal is to add a Sebastian |
The CSSWG will automatically accept this resolution one week from now if no objections are raised here. Anyone can add an emoji to this comment to express support. If you do not support this resolution, please add a new comment. Proposed Resolution: Add a |
-1 to the proposal, mainly because having |
I don't understand your objection, @fantasai. We virtually never use plurals in property names, even tho a lot of properties are comma-separated multiple instances. Specifically *in the It would be a pretty big break from tradition to suddenly have one |
@tabatkins I'm not arguing for plural, I'm just arguing against |
What about
|
Not the hugest fan of that, since a background is, itself, an underlay for the element. ^_^ |
A few ideas
|
Maybe |
What about |
Can I confirm if I understand the proposal correctly? Would the proposal introduce a new way to control backgrounds, that instead of overriding, would combine, blend or overlay backgrounds from different rules? For example: .foo {
background-layer: red;
}
.bar {
background-layer: url("image.png") no-repeat right top;
}
.baz {
background-layer: url("image2.png");
} Would be equivalent to computed CSS of background: red, url("image.png") no-repeat right top, url("image2.png"); If so, I feel like Rereading the thread, my hunch is that, this is not what's being proposed. 🤔 |
@gavinmcfarland You are misunderstanding, this proposal is for a normal shorthand, not for additive cascade. It would just allow writing background: url("image.png") no-repeat right top, url("image2.png") red; as background-something: url("image.png") no-repeat right top, url("image2.png");
background-color: red; |
Perhaps it's overkill, but could we draw inspiration from other CSS properties. Like For example: div {
background-layers: "base" "artwork";
}
.foo {
background-layer: "base";
background: red;
}
.bar {
background-layer: "artwork";
background: url("image.png") no-repeat right top;
} Which would compute to: background: red, url("image.png") no-repeat right top; I feel like this could play nicely with existing conventions and understanding of the |
Additive cascade is off-topic for this issue, it's discussed in #1594 instead. |
Thanks @Loirooriol for clarifying. So it is quite literally just another property that excludes I'm not sure I'm in favour of this. I think it could introduce more confusion about the use of the existing I like the intent of the proposal, just not sure if I agree with the suggested implementation. |
Ok, thank you. I'll take a look at that issue. Perhaps then there's a chance that resolves the need for this proposal? |
I gotta agree with this, and I don’t think it’s particularly confusing, considering that despite background being an element underlay, it’s still got multiple layers, and the motivation for this specific feature requires that you understand that mental model. |
I feel like the current proposal is a bit confusing because people already know I'm sympathetic to the use case though and I'd suggest a shorthand that covers everything that |
I like this idea too! Maybe something like |
my vote goes to background-stack. I found it more clear. |
Have you considered |
Is a new property a better choice than introducing some inline keyword in |
@gavinmcfarland But that's precisely how the current model works, see https://drafts.csswg.org/css-backgrounds-3/#background-color
Your example with |
I’m fine with the name and concept of foo::background(1) {
content: <background-image>;
top: right: bottom: left: <background-position>;
width: height: <background-size>;
overflow[-x/-y]: <background-repeat>;
position: <background-attachment>;
sizing: <background-origin> <background-clip>;
} |
I like this idea of adding a keyword to reuse a previously defined value. .foo {background:gray;}
.alert {background:red;}
.alert {background:inherit-value url("alert.png") no-repeat right top; /* takes color from .alert */}
.bar {background:inherit-value url("bar.png") no-repeat right top; /* no color found, so behaves like 'inherit' */}
.foo .bar {background:inherit-value url("foo-bar.png") no-repeat right top; /* takes color from .foo */} If the above is not within scope...
|
I don't think it can be a keyword, or be part of the value in general. Another idea could be using #8055, though you would still need to list the longhands once, an ugly universal selector, and a roundabout of setting via variables: * {
background-position: from-shorthand(background: var(--background));
background-repeat: from-shorthand(background: var(--background));
background-attachment: from-shorthand(background: var(--background));
background-image: from-shorthand(background: var(--background));
background-size: from-shorthand(background: var(--background));
background-origin: from-shorthand(background: var(--background));
background-clip: from-shorthand(background: var(--background));
}
.foo { --background: url('foo.png') content-box no-repeat; }
.bar { --background: url('bar.png') 10px 20px no-repeat; } However, I think the best solution (and already works in browsers!) would be setting the full @layer {
.foo { background: url('foo.png') content-box no-repeat; background-color: revert-layer }
.bar { background: url('bar.png') 10px 20px no-repeat; background-color: revert-layer }
} |
A keyword could mean “skip” and at parse time the shorthand could be expanded to every longhand except the skipped ones; that doesn’t seem like an obstacle. |
@Loirooriol You're right, how silly of me. It's been a while since I worked with colours and images together and I don't think I realised that the colour had to be at the end. Ok, now I understand what the problem is. Eek, I'm not sure if there a great alternative. I now realise what Lea was trying to describe. What is currently My best suggestions are:
|
@ljharb Consider this: element.style.cssText = "background: var(--b)";
[...element.style].includes("background-color"); // ??? At specified-value time we don't know whether the variable will have the value that skips |
@Loirooriol i mean, what does it say for that now? |
It says If in #5319 we add |
Yes, that's exactly what i'd say the default should be pending the var's value - but even if the default is |
The problem is that |
Summary of the proposals above:
Sebastian |
|
I think it's worth noting that we have a similar pattern of properties for |
While this is not what the original poster asked for, here is a way to do exactly that: https://schepp.dev/posts/chaining-declarations-with-css-animation-composition/ So maybe the new thing might be based off whatever mechanic is at work here. |
@Schepp Ummmm, no, we definitely should not be using fill-forwards animations to declare normal specified values. :) https://www.w3.org/TR/web-animations-1/#fill-behavior |
Absolutely! 😅 But maybe the fact that this works opens up new ideas. |
The CSS Working Group just discussed
The full IRC log of that discussion<fantasai> SebastianZ: initial proposal was to create background-layers property that is separate from background-color but is otherwise same as 'background' shorhtand<fantasai> -> summary comment https://github.com//issues/8726#issuecomment-1569020794 <fantasai> SebastianZ: The discussion went on and had different proposal to cover that use case <fantasai> SebastianZ: 1st was new shorthand described above <fantasai> SebastianZ: another that includes everything except images and color <fantasai> SebastianZ: third was a ::background() pseudo-element <SebastianZ> https://github.com//issues/8726#issuecomment-1569020794 <fantasai> SebastianZ: fourth was to add new keyword to skip overwriting the color <fantasai> SebastianZ: and last was from Oriol to make no change, but teach authors to use background-color: revert-layer <Rossen_> q? <fantasai> SebastianZ: My personal opinion is to have something like the original proposal <fantasai> SebastianZ: from my view it's the easiest way to achieve this as an author <fantasai> SebastianZ: other suggestions have adantages as well <fantasai> fantasai: agree with SebastianZ <ntim> q+ <fantasai> fantasai: tackling list-editing cascade is a big project, worth doing, but unnecessary <Rossen_> ack fantasai <Rossen_> ack ntim <fantasai> fantasai: just adding a shorthand is simple and solves the problem, biggest problem is naming the shorthand <miriam> q+ <fantasai> ntim: Problem is you'll have 3 properties with similar syntax, hard to know the differences <fantasai> ntim: you can do background: url, url, and then background-image: url, url; and then background-layers: url, url <fantasai> miriam: I agree with SebastianZ and fantasai <Rossen_> ack miriam <fantasai> miriam: I mostly wanted to push against the 'revert-layer' option <fantasai> miriam: teaching authors to use revert-layer is great! but it has specific cases where that's useful solution <fantasai> miriam: but it requires adding new layers, and want to do that carefully <fantasai> miriam: doesn't make sense as a universal solution to this problem <fantasai> ??: I had a proposal to put positioning into shorthand without image, to avoid confusion of three properties that can take an image <fantasai> s/??/ntim/ <fantasai> SebastianZ: that was my second option <drott> fantasai: not a good idea, then you'd have to maintain two lists <Rossen_> ack fantasai <drott> fantasai: 1 for images, 1 for positioning <drott> fantasai: sometimes there's use cases for splitting those things - but images and positioning are cascading together, so they should be declared together <drott> fantasai: i'd advocate for original proposal, just need a shorthand name that makes sense <fantasai> Rossen_: sounds like many folks leaning towards original proposal <fantasai> Rossen_: would there be objections to resolve on the original proposal, and naming later? <fantasai> RESOLVED: add shorthand for background-* minus background-color, name TBD |
spec: https://w3c.github.io/csswg-drafts/css-backgrounds/#the-background
We often run into situations where
background-color
has already been set for an element or component, and in a separate class we want to also add a background image to it.In order to do this without overriding the color, we have to use the
background-image
property specifically.Then we need to size, position, no-repeat it and that's 3 more longhand properties.
Add two bg images and we're managing parallel arrays in every longhand property above to avoid overriding the background-color set elsewhere.
It gets pretty tedious very quickly.
Fortunately, the spec already defines a
<bg-layer>
so it may not be a big ask to addbackground-layers
as a shorthand property that defines everything for a background, excludingbackground-color
.background-layers = <bg-layer># | none
(suggesting plural
background-layers
even though the longhand bg properties are singular since they predate multiple image layers)Thank you!
The text was updated successfully, but these errors were encountered: