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
[cssom][css-position] Resolved value of over-constrained percentages in inset properties #3059
Comments
In fact what CSSOM says (without taking CSS Position into account) doesn't match any implementation. Consider this code: https://jsfiddle.net/s6qgo0L3/<pre id="log"></pre>
<div id="container">
<div id="relative">
<div id="static"></div>
</div>
</div> #container {
height: 100px;
width: 100px;
}
#relative {
position: relative;
top: 10%;
left: 20%;
bottom: 30%;
right: 40%;
}
#static {
top: inherit;
left: inherit;
bottom: inherit;
right: inherit;
} function insets(el) {
let {top, bottom, left, right} = getComputedStyle(el);
return JSON.stringify({top, bottom, left, right});
}
log.textContent = insets(relative) + "\n" + insets(static); From https://drafts.csswg.org/cssom/#resolved-value-special-case-property-like-top
The relative element is overconstrained, so we should get the computed value. All Firefox, Chromium, WebKit and Edge provide an absolute length and not a percentage:
The static element uses However, all Firefox, Chromium and Blink provide the percentage instead:
Edge absolutizes the percentages even is static positioning, but they are different this time because they have been resolved with respect to the relative element instead of the container ancestor:
We can conclude that the computed value of the relative element is the percentage, and So I think CSSOM should say something like:
And then in CSS Position
(which is what CSS2 says a bit summarized) Cc @emilio |
That's not true, the computed value is still the percentage. |
Sorry, pressed enter too early. You did notice that below:
That's exactly right. I think your proposal makes sense. Though why do you think css-position should change? The sentence:
Looks ok to me, though it could be reworded as you say I guess. |
Because before 6516a86 the computed value of a percentage was not clear at all. And the spec hadn't been updated when I posted my previous comment. Now I guess it's OK. |
CSSOM says for
top
,right
,bottom
andleft
:Therefore, if I use
since relative positioning doesn't stretch boxes, there is over-constrainment, so I should get the computed value.
So what's the computed value of a percentage? https://drafts.csswg.org/css-position-3/#box-offsets-trbl says
Relative positioning doesn't mention percentages, so it seems it should be the specified value according to "otherwise". But that's not the case in Firefox and Blink, which return the absolute length instead.
WebKit returns the used value when there is over-contraintment and I want to implement the proper behavior, which is not clear.
The text was updated successfully, but these errors were encountered: