【问题标题】:Font size changes in fullscreen on mobile手机全屏字体大小变化
【发布时间】:2021-02-13 02:32:58
【问题描述】:

在让我的一个网络应用程序响应时,我遇到了一个非常奇怪的问题。 元素的字体大小在切换全屏时变化很大。我在 Chrome DevTools 仿真和真实手机上的 Chrome 中都发现了这个问题。

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

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

#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>

【问题讨论】:

    标签: html css google-chrome responsive-design font-size


    【解决方案1】:

    编辑:经过一些经典的反复试验,结论终于浮出水面。

    这里的罪魁祸首是缺少viewport meta tag

    基本示例: &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;

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

    【讨论】:

    • 相对单位没有搞砸,请参阅更新后的问题。
    • 我什至尝试删除font-size: 80%,但没有成功。
    • 我能问一下为什么user agent stylesheet 包含在您的CSS 中吗?当您没有包含自己的样式时,这些是 Google Chrome 提供的默认样式。 - 您没有包含您的 HTML,但您能否确保您的 HTML 文档中包含 &lt;!DOCTYPE&gt;
    • 为了让回答者满意,我还包括了浏览器应用的样式,但用user agent stylesheet 标记了它们。是的,我已经包括了序言。 HTML 没有太多,我认为它不会导致问题,但我已将其包含在更新的答案中。
    • 我想通了,我错过了添加视口meta 标签,谢谢你提醒我检查我的HTML。如果您用解决方案更新答案,我会接受。
    猜你喜欢
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多