85

Our site renders with inconsistent font sizes on mobile Safari -- and as far as we can tell, only Mobile Safari. This very much has stumped us.

We analyzed the site with Firebug, and the incorrect areas are inheriting the right styles, yet the fonts are still rendered with the wrong sizes.

1) Visit http://www.panabee.com.

2) Conduct a search for a domain name.

The boxes on the left side show the incorrect font sizes. The font size should match the font size on the right side (both box titles and box copy). For instance, the titles, "Variations" and "Twitter," are much larger than the title, "Alternate Endings."

Any clue why?

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Crashalot
  • 33,605
  • 61
  • 269
  • 439

6 Answers6

159

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.

Pathogen David
  • 619
  • 6
  • 9
John Mellor
  • 12,572
  • 4
  • 46
  • 35
  • Thanks, @John. When you say "blocks of text," are you referring to the text's parent container, or the actual amount of text? In other words, for the section titles like "Variations" and "Translations" which only contain text a few chars long, I would need to wrap them inside another DOM element (e.g., span with display of inline-block)? – Crashalot Apr 04 '11 at 19:11
  • @Crashalot: By blocks of text I mean elements with `display:block`, like

    tags. In your case it seems you could just make both your columns 320px wide - see the example CSS I added to my answer above (this could probably be improved to better handle screen size variations). Where possible, test how it looks on real devices. You can optimize further though, for example have expandable sections like http://en.m.wikipedia.org/wiki/Mobile_Web so the user doesn't have to scroll so much to find the sections that interest them.

    – John Mellor Apr 07 '11 at 14:30
  • pls note the actual solution is below. we awarded @John the points since he inspired the final solution. – Crashalot Jul 03 '12 at 19:24
  • @John: What if I'd use responsive webdesign? What would be the solution there? The only option I came up with is setting a width on the block element (`p`). But than I'd have to be aware an all sizes and orientation ... I only want that two `p` elements have the same font-size ... – testing Oct 09 '13 at 16:29
  • 1
    @testing: Text Autosizing only affects columns of text that are wider (in CSS pixels) than the device's screen width (in density-independent pixels). If you use responsive webdesign you'll have or equivalent, which means your page will never be wider than the device's screen, so Text Autosizing will have no effect, and you don't need to worry about it. (There's a slight caveat in Chrome for Android - http://crbug.com/252828 - but even that should usually be relatively minor). – John Mellor Oct 11 '13 at 15:44
  • 3
    Regarding The Quest for Responsive Web Design: there were situations during my Quest where a device-width-specific Responsive Design still broke, with some fonts just randomly changing size when rotated on the iPhone, despite working perfectly on the desktop in Safari and Chrome. This CSS fix ( -webkit-text-size-adjust: 100% ) seems key to allowing a developer/designer to actually achieve a responsive design. I tried weird JavaScript fixes and despite , nothing but this CSS actually worked. – Jared Updike May 06 '16 at 18:54
42

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.

Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • 4
    For completeness, this is the whole declaration: `-webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;` – Claudiu Creanga May 27 '15 at 10:35
6

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

SztupY
  • 10,291
  • 8
  • 64
  • 87
Webreality
  • 623
  • 1
  • 6
  • 11
3
-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.

alex
  • 479,566
  • 201
  • 878
  • 984
Thomas Maas
  • 1,999
  • 12
  • 8
  • 3
    Thanks, @Thomas. This isn't quite sufficient because it also disables resizing of the font as users zoom in and out, which is undesirable. The goal is to preserve Safari's resizing based on zooms while also preserving font size consistency as defined by the CSS. – Crashalot Mar 22 '11 at 23:37
2

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.

cSn
  • 2,796
  • 3
  • 23
  • 29
0

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.
     }
SantoshK
  • 1,789
  • 16
  • 24