-
Notifications
You must be signed in to change notification settings - Fork 657
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-media-queries] css media query width and window.innerWidth may not be equal #4713
Comments
I suppose we could specify that media queries round up the the closest integer pixel value before doing the comparison, but while this would solve this particular problem, this would cause the opposite problems when using inequalities: So they may not be equal, for example: Hopefully we can fix this problem on the cssom side, but even if we cannot, given that width mediaqueries are more useful for inequalities than for equalities, I'm inclined to keep the behavior of mediaqueries unchanged. |
The CSS Working Group just discussed
The full IRC log of that discussion<heycam> Topic: css media query width and window.innerWidth may not be equal<heycam> github: https://github.com//issues/4713 <heycam> florian: MQs lets you test the width (and height) <heycam> ... of a page, and the MQ works in terms of floating point numbers <heycam> ... there is also window.innerWidth, which relates to the same dimension, but it's an integer <heycam> ... the fact that they're different is weird <heycam> ... if you test the MQ against a value against the window.innerWidth you may get surprising results <heycam> ... a strict equality MQ could fail <heycam> ... in practice min-/max- is better. but this is odd, not sure what to do about that <heycam> Rossen_: this is when you use window.matchMedia() with a value from window.innerWidth? <Rossen_> "window.matchMedia('(width > window.InnerWidth)') << this is a problem <heycam> dbaron: I think one thing that could be done is to propose an API that is better than window.innerWidth, and returns the float values <heycam> Rossen_: I guess the questions that is MQ-scoped, is there anything we should be looking at doing for the MQ width or not? <dbaron> (I think that's a thing that could be done by anyone who thinks this is an issue for them!) <heycam> florian: I would like to not change it. but given I don't know how/whether to solve it... <heycam> ... so would rather go in dbaron's direction <heycam> ... rather than change MQs to work on integers <heycam> Rossen_: the usage of @media width is very high <heycam> ... making a change would be very disruptive, don't think we have that option <heycam> Rossen_: any objections to not change @media width/height? <heycam> RESOLVED: No change to @media width/height <Rossen_> Zakim, end meeting <Zakim> As of this point the attendees have been Rossen_, plinss, fantasai, stantonm, dbaron, faceless2_, GameMaker, jensimmons, heycam, miriam, chris, chrishtr, dino, drousso, leaverou, |
…reater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS @media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > @media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokan@chromium.org> > Reviewed-by: David Bokan <bokan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#680047} TBR=dcheng@chromium.org,bokan@chromium.org,majinfeng1@xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec
…reater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS @media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > @media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokan@chromium.org> > Reviewed-by: David Bokan <bokan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#680047} TBR=dcheng@chromium.org,bokan@chromium.org,majinfeng1@xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokan@chromium.org> Commit-Queue: Jinfeng Ma <majinfeng1@xiaomi.com> Cr-Commit-Position: refs/heads/master@{#775490}
…reater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS @media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > @media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokan@chromium.org> > Reviewed-by: David Bokan <bokan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#680047} TBR=dcheng@chromium.org,bokan@chromium.org,majinfeng1@xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokan@chromium.org> Commit-Queue: Jinfeng Ma <majinfeng1@xiaomi.com> Cr-Commit-Position: refs/heads/master@{#775490}
…reater than 1." This reverts commit 6c7fa9e. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS @media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > @media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokan@chromium.org> > Reviewed-by: David Bokan <bokan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#680047} TBR=dcheng@chromium.org,bokan@chromium.org,majinfeng1@xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokan@chromium.org> Commit-Queue: Jinfeng Ma <majinfeng1@xiaomi.com> Cr-Commit-Position: refs/heads/master@{#775490}
…work if devicePixelRatio is greater than 1.", a=testonly Automatic update from web-platform-tests Revert "CSS @media (width: *px) may not work if devicePixelRatio is greater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS @media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > @media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokan@chromium.org> > Reviewed-by: David Bokan <bokan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#680047} TBR=dcheng@chromium.org,bokan@chromium.org,majinfeng1@xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokan@chromium.org> Commit-Queue: Jinfeng Ma <majinfeng1@xiaomi.com> Cr-Commit-Position: refs/heads/master@{#775490} -- wpt-commits: 7e369076c1a0f9549310f0229eb202e58c14382b wpt-pr: 23974
…work if devicePixelRatio is greater than 1.", a=testonly Automatic update from web-platform-tests Revert "CSS @media (width: *px) may not work if devicePixelRatio is greater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS @media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > @media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokan@chromium.org> > Reviewed-by: David Bokan <bokan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#680047} TBR=dcheng@chromium.org,bokan@chromium.org,majinfeng1@xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokan@chromium.org> Commit-Queue: Jinfeng Ma <majinfeng1@xiaomi.com> Cr-Commit-Position: refs/heads/master@{#775490} -- wpt-commits: 7e369076c1a0f9549310f0229eb202e58c14382b wpt-pr: 23974
…ork if devicePixelRatio is greater than 1.", a=testonly Automatic update from web-platform-tests Revert "CSS media (width: *px) may not work if devicePixelRatio is greater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokanchromium.org> > Reviewed-by: David Bokan <bokanchromium.org> > Cr-Commit-Position: refs/heads/master{#680047} TBR=dchengchromium.org,bokanchromium.org,majinfeng1xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokanchromium.org> Commit-Queue: Jinfeng Ma <majinfeng1xiaomi.com> Cr-Commit-Position: refs/heads/master{#775490} -- wpt-commits: 7e369076c1a0f9549310f0229eb202e58c14382b wpt-pr: 23974 UltraBlame original commit: da6eb0de8359a3dde49f73849690dd4a94101813
…ork if devicePixelRatio is greater than 1.", a=testonly Automatic update from web-platform-tests Revert "CSS media (width: *px) may not work if devicePixelRatio is greater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokanchromium.org> > Reviewed-by: David Bokan <bokanchromium.org> > Cr-Commit-Position: refs/heads/master{#680047} TBR=dchengchromium.org,bokanchromium.org,majinfeng1xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokanchromium.org> Commit-Queue: Jinfeng Ma <majinfeng1xiaomi.com> Cr-Commit-Position: refs/heads/master{#775490} -- wpt-commits: 7e369076c1a0f9549310f0229eb202e58c14382b wpt-pr: 23974 UltraBlame original commit: da6eb0de8359a3dde49f73849690dd4a94101813
…ork if devicePixelRatio is greater than 1.", a=testonly Automatic update from web-platform-tests Revert "CSS media (width: *px) may not work if devicePixelRatio is greater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokanchromium.org> > Reviewed-by: David Bokan <bokanchromium.org> > Cr-Commit-Position: refs/heads/master{#680047} TBR=dchengchromium.org,bokanchromium.org,majinfeng1xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokanchromium.org> Commit-Queue: Jinfeng Ma <majinfeng1xiaomi.com> Cr-Commit-Position: refs/heads/master{#775490} -- wpt-commits: 7e369076c1a0f9549310f0229eb202e58c14382b wpt-pr: 23974 UltraBlame original commit: da6eb0de8359a3dde49f73849690dd4a94101813
…reater than 1." This reverts commit 6c7fa9eae2437a99d8a4f1b0835030b688bc9285. Reason for revert: w3c/csswg-drafts#4713 Original change's description: > CSS @media (width: *px) may not work if devicePixelRatio is greater than 1. > > When devicePixelRatio is greater than 1, the viewport size of the CSS media > query may appear as non-integers. This can happen in Chrome for Android if > the UseZoomForDSF flag is enabled. > > For example: > <meta name="viewport" content="width=device-width, initial-scale=1"> > <style> > @media (width: 393px) { > p { > color: red; > } > } > </style> > <p>text</p> > > If the device width is 1081 physical pixels and devicePixelRatio is 2.75. The > viewport width of the CSS media query will be 393.091px. > > Change-Id: I25ee4da1ebdbd57202fa8c5e360138a8058f578f > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695522 > Commit-Queue: David Bokan <bokan@chromium.org> > Reviewed-by: David Bokan <bokan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#680047} TBR=dcheng@chromium.org,bokan@chromium.org,majinfeng1@xiaomi.com Bug: 1043456 Change-Id: Idd69f034a59a3161b244c0921637e787118718ec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228028 Reviewed-by: David Bokan <bokan@chromium.org> Commit-Queue: Jinfeng Ma <majinfeng1@xiaomi.com> Cr-Original-Commit-Position: refs/heads/master@{#775490} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: c244cefe5c7761cf986c490f4e5ba06b702d06bd
According to the CSS specifications, both of them are the width of the viewport: [1], [2]. So they should be equal. But the window.innerWidth is a signed integer while media queries can specify float precision: [1], [3].
So they may not be equal, for example:
Web page zoom level: 300%;
Physical pixel width: 1000px;
"window.matchMedia('(width: ' + window.innerWidth + 'px)').matches" will be set to false.
References:
The text was updated successfully, but these errors were encountered: