手机全屏字体大小变化

Font size changes in fullscreen on mobile

在使我的一个 Web 应用程序响应时,我遇到了一个非常奇怪的问题。 元素的字体大小在切换全屏时变化非常大。我在真实移动设备上的 Chrome DevTools 仿真和 Chrome 中都发现了这个问题。

以下屏幕截图显示了问题所在。请注意,部分屏幕截图已针对隐私进行了审查,但 显示了所有重要部分。(窗口模式与全屏模式)

应用于这些元素的所有 CSS 如下。如您所见,两种模式之间没有 CSS 发生变化。那么为什么会发生这种情况,我该如何阻止呢?
我也看过 Computed Styles,它也保持不变。窗口和全屏模式的计算样式都是 16px,即相对单位没有搞乱。

#a11y-controls button {
    border: none;
    border-radius: 0;
    border: 1px solid #555;
}
body.a11y button:focus {
    box-shadow: 0 0 0 2px inset #4c9aff;
    outline: none;
}
button:focus {
    border-color: white;
}
button:hover {
    background: #555;
}
button {
    font: inherit;
    font-size: 80%;
    background: #000;
    color: white;
    border: 1px solid #555;
    border-radius: 3px;
    padding: 5px 10px;
    cursor: pointer;
}
* {
    box-sizing: border-box;
}
user agent stylesheet
:focus {
    outline: -webkit-focus-ring-color auto 1px;
}
user agent stylesheet
button {
    appearance: button;
    -webkit-writing-mode: horizontal-tb !important;
    text-rendering: auto;
    color: -internal-light-dark(black, white);
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    display: inline-block;
    text-align: center;
    align-items: flex-start;
    cursor: default;
    background-color: -internal-light-dark(rgb(239, 239, 239), rgb(59, 59, 59));
    box-sizing: border-box;
    margin: 0em;
    font: 400 13.3333px Arial;
    padding: 1px 6px;
    border-width: 2px;
    border-style: outset;
    border-color: -internal-light-dark(rgb(118, 118, 118), rgb(133, 133, 133));
    border-image: initial;
    border-radius: 2px;
}
@media (pointer: coarse)
#a11y-controls {
    height: 100px;
    bottom: -100px;
    font-size: 20px;
}
Style Attribute {
    pointer-events: all;
}
body {
    pointer-events: none;
    position: relative;
}
body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: black;
    color-scheme: dark light!important;
    font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

在全屏模式下,

#a11y-controls button {
    border: none;
    border-radius: 0;
    border: 1px solid #555;
}
body.a11y button:focus {
    box-shadow: 0 0 0 2px inset #4c9aff;
    outline: none;
}
button:focus {
    border-color: white;
}
button:hover {
    background: #555;
}
button {
    font: inherit;
    font-size: 80%;
    background: #000;
    color: white;
    border: 1px solid #555;
    border-radius: 3px;
    padding: 5px 10px;
    cursor: pointer;
}
* {
    box-sizing: border-box;
}
user agent stylesheet
:focus {
    outline: -webkit-focus-ring-color auto 1px;
}
user agent stylesheet
button {
    appearance: button;
    -webkit-writing-mode: horizontal-tb !important;
    text-rendering: auto;
    color: -internal-light-dark(black, white);
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    display: inline-block;
    text-align: center;
    align-items: flex-start;
    cursor: default;
    background-color: -internal-light-dark(rgb(239, 239, 239), rgb(59, 59, 59));
    box-sizing: border-box;
    margin: 0em;
    font: 400 13.3333px Arial;
    padding: 1px 6px;
    border-width: 2px;
    border-style: outset;
    border-color: -internal-light-dark(rgb(118, 118, 118), rgb(133, 133, 133));
    border-image: initial;
    border-radius: 2px;
}
@media (pointer: coarse)
#a11y-controls {
    height: 100px;
    bottom: -100px;
    font-size: 20px;
}
Style Attribute {
    pointer-events: all;
}
body {
    pointer-events: none;
    position: relative;
}
body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: black;
    color-scheme: dark light!important;
    font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

为了让您满意,这就是用于处理全屏模式切换的所有 javascript。

function toggleShotMode() {
    if (document.fullscreenElement === null) {
        //!titleInShot.checked ? picTitle.style.opacity = 0 : picTitle.style.opacity = 1;
        document.documentElement.requestFullscreen();
    } else {
        //picTitle.style.opacity = 1;
        document.exitFullscreen();
    }
}

这里是 HTML,经过删减但显示了重要部分。

<!DOCTYPE html>
<html>

<head>
    <title></title>
    <meta name="color-scheme" content="dark light">
    <link rel="stylesheet preload prefetch" href="https://fonts.googleapis.com/css2?family=Lato&display=swap" as="style">

    <link rel="stylesheet" href="./style.css">
    <link rel="manifest" href="./manifest.webmanifest">
    <link rel="shortcut icon" href="./favicon.ico">
    <link rel="apple-touch-icon" href="./apple-touch-icon.png">
</head>

<body>

    <div id="a11y-controls">
        <button id="a11y-prev-pic">Previous Picture</button>
        <button id="a11y-shot-moder">Toggle "Shot-Mode"</button>
        <button id="a11y-settings-toggler">Open/Close Settings</button>
        <button id="a11y-next-pic">Next Picture</button>
    </div>

    <script src="script.js"></script>
</body>

</html>

编辑:经过一番经典的反复试验,终于得出结论。

这里的罪魁祸首是 viewport meta tag

基本示例: <meta name="viewport" content="width=device-width, initial-scale=1">

在没有规范的情况下,浏览器会尽力在移动屏幕上呈现较大的桌面视图,而无意中忽略了移动设备 CSS。