Re: [csswg-drafts] [css-values-4][cssom] Proposal to allow retrieval of sub-pixel border values (#10729)

I'm hoping to work with the sub-pixel value for two main reasons. The first reason is related to my project, which I'll admit is for sure a specific scenario. The second is that I think it would be consistent with the behavior of other methods, and that there are existing reasons to be interested in sub-pixel values, even if screens can't render them yet.

Specific to my project, if I'm trying to find an element on the page with a specified `border-left-width` of `0.25vw`, then the current behavior makes it difficult, if not impossible, to know when I've found it.

For example, on a screen with a width of `1800px`, the sub-pixel value would be `4.50px`, and it would be snapped to `4px`. When I compute the style and see `4px`, it could mean that `border-left-width` was `0.25vw` and snapped, or it could mean that it was `0.225vw` with no need to be snapped, since `0.225vw` on an `1800px` wide screen is `4px`. There's no practical way to know. You could make an estimate based on other properties, but it still wouldn't be certain.

Your point that it doesn't match reality is correct, and that's something that has to be taken into account. But it would be a more complete picture to have access to pre-snap values. It's a small difference on a per-element basis, but if you're working with a large number of elements, the differences add up.

In regard to consistency, given how precise methods like `getBoundingClientRect` are, and how other properties like `height` and `width` in `getComputedStyle` use sub-pixels, it would be great be able to work with sub-pixel measurements for other size-related properties like `border-width`.

For example, in the script above, I set `width: 22.25vw`, which comes out to `400.50px` on an `1800px` screen. Even though sub-pixels can't be rendered, and the actual `width` in reality isn't `400.50px`, I'm still able to see the sub-pixel value.

Sub-pixels are useful for techniques like anti-aliasing and increasing a screen's effective resolution. This goes to show that there are reasons to be interested in the sub-pixel values, even if modern screens aren't able to render them yet. Since this information is available for other properties, I think it makes sense to make it available for properties like `border-width`.




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


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 14 August 2024 19:46:47 UTC