修正移动 Safari (iPhone)中文本呈现不一致且某些字体大于其他字体的字体大小问题?

我们的网站在移动 Safari 上呈现不一致的字体大小——据我们所知,只有移动 Safari。这让我们很困惑。

我们使用 Firebug 分析了站点,不正确的区域继承了正确的样式,但是字体仍然呈现了错误的大小。

1)参观 http://www.panabee.com

2)进行域名搜索。

左边的框显示了不正确的字体大小。字体大小应该与右侧的字体大小相匹配(包括方框标题和方框副本)。例如,标题“ Variations”和“ Twitter”要比标题“ Alternate Endings”大得多

知道为什么吗?

102132 次浏览
-webkit-text-size-adjust:none;

will probably solve your problem.

target-element { -webkit-text-size-adjust:80% }

will still zoom but keeps it 80% smaller than webkits default.

Mobile Safari (like Chrome for Android, Mobile Firefox and IE Mobile) increases the font size of wide blocks (at all times), such that if you double-tap to zoom in on that block (which fits the block to the screen width), the text will be legible. If you set -webkit-text-size-adjust: 100% (or none), it won't be able to do this, and so when a user double-taps to zoom in on wide blocks the text will be illegibly small; users will be able to read it if they pinch-zoom in, but then the text will be wider than the screen and they'll have to pan horizontally to read each line of text!

  1. Ideally you would fix this by using Responsive Web Design techniques to make your design adapt to mobile screen sizes (in which case you would no longer have any very wide blocks, so mobile browsers would no longer adjust your font sizes).

  2. If that's not an option, and you're stuck serving a desktop site to mobile users, then see if you can tweak your design so none of your blocks of text are wider than the mobile device's device-width (e.g. 320px for many portrait phones) (you can use mobile-specific css to avoid affecting desktop browsers), then Mobile Safari won't need to increase any font sizes (and browsers which reflow text, like the Android Browser and Opera Mobile, also won't need to change your layout).

  3. Finally if you really need to prevent Mobile Safari from adjusting your font sizes you can set -webkit-text-size-adjust: 100%, but do this only as a last resort since it is likely to cause mobile users to have difficulty reading your text, as it'll either be too small or they'll have to pan from side to side after every line they read. Note that you must use 100% not none because none has nasty side-effects in desktop browsers. There are also equivalent -moz-text-size-adjust and -ms-text-size-adjust properties for Mobile Firefox and IE Mobile.

Edit: for example in your case the simplest is probably the 2nd alternative, so you could try adding the following CSS:

/* Mobile browsers only */
@media only screen and (max-device-width: 480px) {
table#all_results {
width: auto;
}
td#main_box {
width: 320px;
}
td#side_box {
width: 320px;
}
}

Though it's not ideal to hardcode 320px like this; you could improve on that by using a variety of CSS media queries, or getting the device-width from JavaScript.

Here's what ultimately worked (tested only on iPhone 4 tho):

/* Mobile browsers only */
@media only screen and (max-device-width: 480px) {
td#main_box { -webkit-text-size-adjust:100% }
}

We awarded the answer to John since his solution was the basis of this one.

Probably not the most elegant answer, but it works.

-webkit-text-size-adjust: none; will cause you to not be able to zoom in mobile devices. You should use 100% instead.

In my case I had a <p> element and I solved this issue by adding:

width: fit-content;

To it. I was able to reproduce this on Safari mobile as well.

I have fixed font sizes issue by using css hack for IOS app and IOS safari browser.

@supports (-webkit-touch-callout: none) {
//you can write your custom css for IOS safari browser.
}