视口单位的字体大小和缩放错误:哪些浏览器受到影响? [英] Viewport-unit font-size and zooming bug: which browsers are affected?

查看:116
本文介绍了视口单位的字体大小和缩放错误:哪些浏览器受到影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当缩放级别未设置为100%时,桌面IE10似乎无法正确缩放其字体大小以视口单位设置的文本.我试图找出受此影响的IE版本(可能还有其他浏览器). 请在您的浏览器中尝试以下示例并报告您的发现:

It seems that desktop IE10 doesn't correctly scale text that has its font size set in viewport units, when the zoom level is not set to 100%. I'm trying to find out which IE versions (and possibly other browsers) are affected by this. Please try this example in your browser and report your findings:

<!DOCTYPE HTML>
<HTML>
<HEAD>
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=ISO-8859-1">
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
DIV:first-of-type {width: 32px; height: 32px; background-color: blue;}
DIV:last-of-type {width: 3.125vw; height: 3.12vw; background-color: red;}
P:first-of-type {font-size: 32px;}
P {font-size: 3.125vw;}
P:last-of-type {font-size: 16px;}
@-webkit-viewport {width: device-width; zoom: 1.0;}
@-moz-viewport    {width: device-width; zoom: 1.0;}
@-ms-viewport     {width: device-width; zoom: 1.0;}
@-o-viewport      {width: device-width; zoom: 1.0;}
@viewport         {width: device-width; zoom: 1.0;}
</STYLE>
</HEAD>
<BODY>
<DIV></DIV>
<P>font-size: 32px</P>
<DIV></DIV>
<P>font-size: 3.12vw</P>
<P>Resize the window to see the expected behaviour.<BR>
   Zoom in/out to see IE's erratic behaviour:<BR>
   the DIV adapts to the new viewport width,<BR>
   but the font size doesn't.</P>
</BODY>
</HTML>

推荐答案

这是一个简单的解决方法:字体大小以百分比设置,并且触发尺寸调整的脚本根据主体宽度设置主体字体大小. > 但是,我仍然想知道启用此替代方法所需的浏览器和版本.请尝试问题中的示例,并在调整窗口大小和缩放窗口时报告您的平台,浏览器,版本和观察到的行为.

This is a simple workaround: the font sizes are set in percentages, and a resize-triggered script sets the body font size according to the body width.
However, I'd still like to know which browsers and versions I need to enable this workaround for. Please try out the example in the question, and report your platform, browser, version, and the observed behaviour when resizing and zooming the window.

<!DOCTYPE HTML>
<HTML>
<HEAD>
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=ISO-8859-1">
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
BODY {font-size: 16px;}
DIV:first-of-type {width: 32px; height: 32px; background-color: blue;}
DIV:last-of-type {width: 3.12vw; height: 3.12vw; background-color: red;}
P:first-of-type {font-size: 32px;}
P:last-of-type {font-size: 200%;}
@-webkit-viewport {width: device-width; zoom: 1.0;}
@-moz-viewport    {width: device-width; zoom: 1.0;}
@-ms-viewport     {width: device-width; zoom: 1.0;}
@-o-viewport      {width: device-width; zoom: 1.0;}
@viewport         {width: device-width; zoom: 1.0;}
</STYLE>
<SCRIPT>
function addEvent(el, ev, eh, el2, ev2, eh2)
{
    if (el.addEventListener)
    {
        el.addEventListener(ev, eh, false);
    }
    else if ((el2 || el).attachEvent)
    {
        (el2 || el).attachEvent("on" + (ev2 || ev), eh2 || eh);
    }
}
function fontSizeFix()
{
    /* if (navigator.userAgent.search(/\bMSIE\s(9\.|10\.).*\bWindows\s(?!(CE|Phone))/i) > -1) */
    {
        if (document.body)
        {
            addEvent(window, "resize", textSize);
            textSize();
        }
        else
        {
            addEvent(document, "DOMContentLoaded", fontSizeFix, window, "load");
        }
    }
    function textSize()
    {
        var w = document.documentElement.clientWidth || document.body.clientWidth || window.innerWidth;
        document.body.style.fontSize = 1.6 * w / 100 + "px";
    }
}
fontSizeFix();
</SCRIPT>
</HEAD>
<BODY>
<DIV></DIV>
<P>font-size: 32px</P>
<DIV></DIV>
<P>font-size: 200%</P>
</BODY>
</HTML>

这篇关于视口单位的字体大小和缩放错误:哪些浏览器受到影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆