-
Notifications
You must be signed in to change notification settings - Fork 694
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-values-4] Clarify how and when the initial containing block and visual viewport may deviate #5777
Comments
Just to clarify a point of terminology, from the linked article (which is very well put together, by the way - thanks!):
What you're describing as "Initial Containing Block" here is actually what we usually call the "Layout Viewport". The initial containing block as defined in CSS2 is a layout-only concept and conceptually doesn't ever change position, even when you scroll. The "layout viewport" isn't specified but the behavior is fairly interoperable - it is a viewport in the sense that it's position changes as the user scrolls. Its size is by definition the size of the visual viewport at minimum scale. Position: fixed elements use this as their containing block - meaning they resolve percentage based sizes from this (hence, a So, if I understand correctly, your proposal is the have the layout viewport and ICB always match (allowing some temporary disagreement). Is this not just going back to the way things were when hiding and showing the URL bar would resize the ICB? We changed to a model where the ICB isn't resized since experience showed it made many common use cases for vh unusable. I don't see how this proposal addresses the concerns that led to that change in the first place.
I don't think this is true. The current behavior has been in place and interoperable for the last few years at least (in addition to the problem sites we had prior to the change). Any page that, for example, sets font size based on vh will now have a UX destroying reflow on each change in scroll direction anytime the URL bar is shown/hidden. I think what you're suggesting is that there are use cases where a page actually wants this dynamic, resizing layout viewport as the source for vh units. I believe that's true but using this as a default behavior for Assuming you can't build your layout on Regarding more general URL bar behavior and design in browsers - I would point out this is an extremely constrained and complex area. The URL bar is the primary security surface for mobile browsers and the most user visible piece of UI. Making changes to this is extremely difficult; much more so than how the URL bar interacts with layout and page APIs (which is merely "very" difficult). |
Thanks @bokand. There's a lot said here. I suspect that quite a bit of it is talking at cross-purposes or misunderstood, mainly because of my lack of a grip on the terminology. So, let's see if we can address that first, and maybe I can produce an updated article correcting what needs to be corrected and we can go from there.
Gah... You're right. Every time I think I've understood what the Initial Containing Block is, it turns out I haven't! The thing that I've referred to as the Initial Containing Block isn't. I think the main issue is that it is defined as being pinned to the document origin, whereas I've got mine shifting around in the article. How about its size? To keep things simple, let's consider the case where there are no toolbars that might hide/reveal themselves complicating matters.... Does the ICB change size, and if so, in response to what? I presume it changes size in response to viewport resize (e.g. change from portrait to landscape on mobile, or browser window resize on desktop.) Does it also expand on pinch-zoom on mobile? Once I've got ICB properly pinned down, we can come onto Layout Viewport (if you don't mind taking the time to educate me?!) Thanks. |
👍
On desktop the ICB is very simple; it changes size only when you resize the window. Here, the layout viewport will always be the same size as the ICB. (ICB size doesn't ever change in response to pinch-zoom). Mobile is where things get complicated. On mobile, the ICB can change size if the window is resized, via rotation or with the on-screen-keyboard appearing (though I think this varies by browser). It doesn't change size from the URL bar coming in and out. However, its size can be disconnected from device dimensions using the However, things get extra wonky in the edge cases. Three important points:
This means authors can explicitly, and separately, control the size of both the ICB and the layout viewport. Here's an illustrative example: <meta name="viewport" content="width=1000,minimum-scale=4">
<style>
html {
width: 250px;
}
</style>
<!-- Assume content doesn't overflow <html> --> Loaded on a mobile device with a 500px screen width we get:
If we remove the
However, if we now add
All this to the point: the layout viewport and the initial containing block, despite being mostly equivalent in typical, well-behaved cases, can actually vary quite widely. If I remember correctly, |
@mind-bending-forks, in the example pages in sections 2.2 and 2.3 of this article, is the content truncation problem you describe resolved if you use |
that should work in that simple case, but it doesn't solve the need for having an accurate value for |
I understand that. My point is, if |
I can't keep up with you all. Every time I get my head around a post and am drafting a reply, another one appears! In reply to @bokand. So things are complicated by the fact that each browser is slightly different in its implementation. That said, in summary, if you consider the simpler case where there are no hide/reveal toolbars, I think following appears to be true of the ICB based on what you have said:
Is that more-or-less correct? It's the last bullet which is most surprising/puzzling to me. The EDIT: Just realising now that your comment about the ICB not ever changing in size in response to pinch-zoom was probably only in reference to desktop. Whereas on mobile, as I observed, it does change in response to pinch zoom (potentially with limits on zoom set by the viewport In reply to @theres-waldo I've uploaded some additional examples so you can test for yourself. There's a In my tests of these on Android, there are some issues/differences, but not with truncation of content. If anything it's the opposite:
I don't have an iOS device to test on right now I'm afraid. |
It depends on your frame of reference :) Pinch-zooming changes the ratio of CSS pixels to screen pixels. The ICB size remains constant in CSS pixels, and varies in screen pixels, as you pinch-zoom. |
This is the behaviour I had in mind for The question is: are you happy with this behaviour as a page author? |
Thanks @theres-waldo. Wow! I didn't realise I'd need to be Einstein to get my head around positioning a few rectangles 😀 That's a lot of degrees of freedom for my brain to cope with, so please give me some time to digest that.
Regarding Chrome's behaviour, I'll have bit more of a play to be sure, but for this specific holy-grail-type example, yes, it appears I am happy! It would be nicer if there was a way to trigger the address bar to hide and to consume the whole space potentially available as is normally possible, but this is only a minor inconvenience that I'm not that bothered by. Far more important is the fact that the layout (by which I mean header and footer positioning in relation to viewport) and behaviour (scroll) are both consistent across desktop and mobile with no truncation of content. So, while this doesn't necessarily fix the issues with |
OK. I read an understanding css units tutorial and that has helped clear it up for me. I was thinking of changes in size relative to the device/real world. On pinch-zoom on mobile, the ICB expands in terms of physical size (device/screen pixels or inches), but is constant in CSS px as you say. So, |
My input to this thread will likely be minimal over the next week because I've got a lot on. I'd like to do a bit of testing to check my understanding, and then I'll likely be back with some requests for clarification before I update my article. |
@mind-bending-forks Since you last posted to this issue, the CSSWG resolved (and engines implemented) three sets of viewports units: the large (with all temporary UI hidden), small (with all temporary UI shown), and dynamic (whatever UI is actually being shown at the moment) viewport units: https://drafts.csswg.org/css-values-4/#viewport-relative-lengths I think the dynamic viewport units, in particular, address the concern you laid out in the OP. Do you agree? Is there anything else still causing you problems in this regard? |
Hi @tabatkins. Apologies for having gone quiet on this issue back in 2020. At the time, I was hoping to assist with finding a resolution but I found myself getting drowned by emerging personal and work matters and this is one of the things that I had to temporarily stop pursuing. Thank you for alerting me to the CSSWG draft of the CSS Values and Units Module Level 4. I have reviewed my initial submission and associated supported document, to remind myself what I perceived the issues and potential solutions to be. I have also read the CSSWG draft text section on the new support for large, small and dynamic viewport units. I have also created Example 1:
Example 2:
Example 3:
In terms of what's written, the new units do indeed appear to deal with the issue I raised here! In terms of the examples, I wasn't fully able to test this, in the sense of observing dynamic behaviour when the address bar disappears using So, I'm happy for this issue to be closed off now. Thank you! |
Background
This proposal is supported by the following article:
https://mind-bending-forks.github.io/css-viewport-percentage-length-units/
Mobile browsers implement a toolbar hiding/revealing feature that results in the visual viewport changing size and position. Having a dynamically resizing initial containing block may lead to unsightly reflow, and so current design avoids this. An inevitable consequence is that the initial containing block deviates from the visual viewport in the initial un-zoomed state (zero pinch-zoom), and this results in content that would ordinarily be visible being truncated while the toolbars are in view.
An issue arises because of the way the hide/reveal mechanism has been linked to scrolling of the underlying content. There are certain situations, such as when using viewport-percentage length units to create content that fills the viewport and when the content contains sub-regions that are scrollable, where the toolbars (and so truncated content) persist. In the problem cases, this truncation persists indefinitely, or until a user scrolls/swipes the outermost content, and so only if they scroll/swipe the outermost content, and so only if they can scroll/swipe the outermost content (which is not currently always the case).
This proposal seeks to place limitations on content truncation by clarifying that the initial containing block and visual viewport are permitted to deviate, but only briefly/temporarily and for a specific action/purpose, otherwise the initial containing block should be re-aligned with the visual viewport.
This therefore provides guidance to browser developers that may encourage modifications to current design that address or minimise the issues identified above. My hope is that problems with truncation of content currently marked as wont fix will at some point be changed to "let's see what we can do to improve matters" at least.
Proposal
The proposal is for the following text (or some variation on it) to be included in the CSS specification, probably alongside the definition of the initial containing block - which is currently defined at https://www.w3.org/TR/CSS21/visudet.html#containing-block-details:
Advantages
Drawbacks
The drawbacks could be overcome by introducing visual-viewport-percentage units (
vvh
,vvw
) that are calculated relative to the instantaneous visual viewport size. It would then be the responsibility of the web developers to check how well their particular usage of visual-viewport-percentage units works.Alternative and Related Proposals
Current Workarounds
The text was updated successfully, but these errors were encountered: