How can I get line breaks in mobile browsers even when scaling?
I have a very simple web page with one column of text. Here are the relevant parts of CSS:
body { font-size: 100%; margin-left: auto; margin-right: auto; } @media not print { body { width: 41em; max-width: 90%; } }
Goal:
Do not use fixed font sizes, but follow the default font size that the user selected in their browser settings.
If the width of the browser window is very large, do not make the lines too wide (too many characters). Instead, leave space on the left and right.
If the width of the browser window is small (= there is not enough space to display 41 m of text in the current font size at the current zoom level), use line breaks exactly for the entire width of the browser window (with a small margin (100% -90%) ÷ 2 = 5% on the left and right), avoiding horizontal scrolling.
If the user zooms in or out, line interruption adapts correctly. Thus, even when the user is very scalable, there is no need for horizontal scrolling, because the line length is not wider than the browser window.
This works great on desktop browsers. But mobile browsers lie around the viewport. They claim that they have a viewport of about eight hundred pixels in size instead of the actual width of the browser window (this is a "layout viewport" - different from a real "visual viewport" - see http://www.quirksmode.org/mobile/viewports2.html ) So, for mobile browsers, Ive added <"viewport" content="width=device-width, initial-scale=1"/> to HTML and
@viewport { width: 100vw; zoom: 1.0; }
in CSS. Now goals # 1, 2, and 3 also work on Firefox Mobile. But goal number 4 does not. Line breaks do not change on recent Firefox Mobile when scaling or scaling. (Satisfactory fact: on my old standard Android 2.3.6 browser, this works.) I believe that the width of the layout viewport in mobile browsers is determined after the <meta> been read, and this layout looks through the width of the CSS pixel does not change anymore when the user zooms in or out (unlike desktop browsers that use their viewport when scaling). Since max-width: 90%; refers to the viewport (since this is the surrounding container), line breaks no longer change when scaling or scaling. Try http://ryanve.com/lab/dimensions/ , which displays some DOM values using JavaScript. When you launch this site in your desktop browser, you see that window.innerWidth changes when zooming in or out. If you do the same in mobile browsers, the value of window.innerWidth does not change when scaling or exiting. As far as I can see, this behavior is also standard behavior on modern mobile browsers and mobile web pages in general. This is apparently the deliberate choice of mobile browser developers (they also want to show old, desktop optimized, insensitive web pages), but the disadvantage is that you can only work with a virtual “view layout”.
And as far as I know, in CSS there are no units that relate to the actual size of the "visual viewport" instead of the virtual "layout viewport."
So my questions are:
I wonder if there is any clean and standard feature for a web page to get this (scaling + line break) working on mobile browsers like on the desktop version?
/ li>If possible, how exactly can this work (preferably without JavaScript)? The only possibility is a dirty hack that estimates the scaling factor (which, as far as I know, is not available for viewing in the JS browser) in mobile browsers, calculating the "width of the visibility screen" ÷ "screen width" and choosing the viewport accordingly?
source share