iPhone 上的字体大小渲染不一致
我正在测试我的网站,并且在每个浏览器上都工作正常,除了 iphone 浏览器(我认为它是移动 Safari?),它使用比其他浏览器更大的字体呈现一段文本。我已经手动检查了 CSS,并在页面上使用了 firebug,我可以确认我已经为所有这些设置了相同的大小。我该如何解决这个问题?
I’m testing my website and is working fine on every browser, except for the iphone browser (i think it’s mobile Safari?) that renders a piece of text with a bigger font that the rest. I’ve checked the CSS by hands and using firebug on the page and I can confirm I’ve put the same size to all of them. How do I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
为了稍微改进 Lukasz 的想法,请尝试在 CSS 中使用以下规则:
使用值“100%”而不是“none”,允许所有其他基于 Webkit 的浏览器在使用缩放功能时仍然调整文本大小,同时仍然保留原始文本字体大小。
此问题仅在 iPhone 设备上的 safari、opera 等现代浏览器中出现。
解决方案是
使用 -webkit-text-size-adjust: 100% 附加此样式;或-webkit-text-size-调整:无;有了所需的课程,它就可以正常工作。
例子:
我希望仅当请求来自移动设备时才应用该条件。因此,我附加了完全满足我的要求的完整导航路径。
或者
}
两者都会工作得很好。无需应用全身样式
To improve on Lukasz's idea slightly, try using the following rule in your CSS:
Using the value '100%' instead of 'none', allows all other Webkit-based browsers to still resize text when using the zoom function while still preserving your original font size.
This issue is arising only in modern browsers like safari, opera with iPhone device.
Solution is
Append this style with the -webkit-text-size-adjust: 100%; or -webkit-text-size-adjust: none; with required class it works fine.
Example:
I want the condition to be applied only when request comes from mobile. So I have appended the complete navigation path that full fills my requirement.
or
}
both will work fine. No need to apply the styles for complete body
Mobile Safari 确实尝试调整内容,使其默认在屏幕上可读 - 它的默认样式与其他浏览器不同。
我不知道确切的规则 - 但当涉及到字体大小时,它似乎是这样工作的:
段落、列表项或其他“文本”元素内的文本:应用作者的风格而不进行调整。
DIV 或其他非特定元素内的文本:视为“纯文本”并根据 Mobile Safari 的规则“调整”大小。
所以 - 简短的答案是,将文本包装在一个段落中,然后应用字体大小规则。
这是一个快速但肮脏的示例:(
显然,您应该将
font-size
规则移至 CSS 文件)。Mobile Safari does try to adapt content so that it's readable on screen by default - it has different default styles to other browsers.
I don't know the exact rules - but when it comes to font sizes, it seems to work like this:
Text inside a paragraph, list item, or other 'text' element: Apply the author's style without adapting.
Text inside a DIV or other non-specific element: Treat as 'plain text' and 'adapt' the size according to Mobile Safari's rules.
So - the short answer is, wrap your text in a paragraph, and apply the font-size rule to that.
Here's a quick and dirty example:
(obviously, you should move the
font-size
rule to the CSS file).我修复了同样的问题:
从 HTML5Boilerplate 目前它是 此处
I fixed this same issue with:
From HTML5Boilerplate currently it's here
将这样的规则放入您的 CSS 中,您的问题就消失了:
编辑:
更好的解决方案,由user612626,就是使用
100%
而不是none
。Put such a rule in your CSS and your problem is gone:
EDIT:
A better solution, provided by user612626, is to use
100%
instead ofnone
.给正文
font-size:100%
,然后使用“em”方法为网站中的每个元素指定字体大小。
这将使字体大小成为相应浏览器默认字体大小的100%。
例如iPhone safari浏览器有12px = 1em(当然你需要检查本地的默认字体大小)。
那么如果你想要10px的字体大小,只需将其除以12,即“0.83em”
我希望你理解,同时搜索“css emunit”你会得到更好的洞察。
Give body
font-size:100%
,then use "em" method to give font size to every element in your website.
This will make the font size 100% of the default font size by respective browser.
For example iPhone safari browser has 12px = 1em (offcourse you need to check the default font size locally).
Then if you want to have 10px font size, just divide it by 12, i.e "0.83em"
I hope you understand, also search for "css em unit" you will get better insight.
对我来说,其他解决方案不起作用。奇怪的是,我发现的唯一解决方案是将段落容器的宽度增加 2 个像素(通过将左右填充减少 1 个像素)。
这是我试图实现的目标:我希望我的段落适合屏幕的宽度(375px),这样它就不会跳过一行,并且不会在段落周围留下空白。文本。
我尝试了字体大小从 1.12em 到 1.20em 的所有组合,它要么:
...但从来没有达到我预期的完美结果,甚至没有接近体面的。但当我将左内边距和右内边距减少 1 个像素时,问题就消失了。
我使用了
-webkit-text-size-adjust: 100%;
和其他解决方案,但对我有用的是上面的解释。您可以在下图中看到(文本模糊,但您明白了)现在所有空间都已使用并按预期工作。因此,如果您绝望了,请尝试一下此解决方案,即使这不是一个理想的解决方案。For me the other solution didn't work. Oddly enough, the only solution I found was to increase the width of my paragraph container by 2 pixels (by diminihsing the left and right padding by 1 pixel).
Here is what I tried to achieve: I wanted my paragraph to fit the width of the screen (375px), so that it does not skip a line, and so that it does not leave blank space around the text.
I tried all combination with font-size from 1.12em to 1.20em, it would either:
...but never the perfect result I expected, not even near decent. But when I reduced the padding left and padding right by 1 pixel, the problem would disappear.
I used
-webkit-text-size-adjust: 100%;
and other solutions but what worked for me was the above explanation. You can see on the image bellow (text is blurred but you get the idea) that now all space is used and working as intended. So, if you are desperate, give this solution a try even though that's not an ideal fix.