-
Notifications
You must be signed in to change notification settings - Fork 719
idea: CSS non-multiplicative opacity-override property #10214
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
Comments
|
That's not the same, that will apply to anything that is nested, which can totally break the desired effect.
I'm sure it is possible to update the spec so that opacity overrides are applied within the offscreen image in a step prior to compositing that offscreen ancestor, etc. |
The issue here is that descendants' opacities aren't "derived from multiplying with ancestor opacities". A descendant with Because everything is composited together into a single image, if you want something to not be composited with the group, it has to exist fully outside of the group - either completely above everything or completely below everything. Outside of some rare exceptions (top layer, mostly), the DOM's painting model implies that the element isn't a descendant of the partially-transparent ancestor at all. Fundamentally, what's going on here is the difference between group opacity and item opacity. You can find tons of tutorials explaining the same thing (and people asking this exact same question) for graphics programs. |
Just a quick note that while I'm not sure if this is the best solution, big +1 for addressing the pain point: I've definitely had this problem numerous times. |
Adding to what @tabatkins mentioned above, the only way this could be achieved, I think, is if we could instruct the browser to somehow scope elements by isolating them into separate layers, kind of like But this is just complete theoretically sci-fi talking. |
Another sci-fi talking: allow multiple layer trees / paint property trees with non-similar structures. For example, tree 1 for transforms where the |
@tabatkins yeah I understand the spec specifies that, but it is something I bet most people don't know, and the behavior most people see most of the time is basically the equivalent of a simple multiplicative opacity in terms of mental model. Is there a way to make an element break out of the graphics layer into its own (while the parent has opacity < 1)? proposalHow about updating the spec so that at least This would solve the OP because to "highlight" an element you could break it out in 3D space (even just a small amount that is not noticeable by the naked eye) and it would be its own new graphics layer with its own opacity, without having to change the shape of the DOM tree and using only CSS styling. This would also be more like how actual 3D engines work. Flattening, f.e. as if setting a 3D node's scale.z to zero, when the tree node has opacity < 1, is nonsensical in all 3D engines that I know of. This is very surprising behavior for 3D in CSS. |
Uh oh!
There was an error while loading. Please reload this page.
Sometimes we'd like to make a parent/ancestor have opacity less than one, but would like some child not to be affected or to have a different opacity.
This can sometimes be achieved with
background-color: rgba()
when it is specifically the background content that should have different opacity than children, but it solves the problem only part of the time.It would be nifty to have a way to override the opacity of a child such that it is not multiplied with any ancestor opacity, but instead starts with a value as if ancestor opacities are all 1.
For example, currently, the following results in an ancestor having visual opacity 0.5, and a descendant having visual opacity of 0.4:
With a new property named
opacity-override
(or something) we could force the descendant to have a specific opacity not derived from multiplying with ancestor opacities:This would be very useful for cases when we'd like to dim all content except to highlight a particular piece of the content, without having to resort to drastic changes to DOM structure (someone may only be editing CSS, and does not want to have to refactor code spread across UI components, for example). In this use case, we might want to use opacity override
1
so that all content in some ancestor is faded out except for some highlighted descendant:The text was updated successfully, but these errors were encountered: