Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobile Chrome: Wrong 'font-size' when using 'height' property

By setting a css 'height' property on a parent container 'foo' the calculated 'font-size' of the inner elements changes wrongly. This happens only on a mobile device on Chrome.

To test this please try to run the following code under Chrome and choose any mobile device in the developer console:

<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>Test</title>
    <style>

        .foo {
            height: 600px;
            color: white;
            background: teal;
        }
    </style>
</head>
<body>
        <section>
            <h2>Header in first section</h2>
            <p>Text with a normal size. Text with a normal size.</p>
        </section>
        <section class="foo">
            <h2>Header in second section</h2>
            <p>This text changes size when commenting out 'foo's height property in the Chrome developer console and mobile mode (e.g Galaxy S5) - but why?</p>
        </section>
</body>
</html>

Then disable (comment out) the 'height' property on the class 'foo'. The calculated 'font-size' for the p-element should not change but it does.

Chrome also shows the wrong size when commenting out the 'height' property in the document itself and reloading the page (-> then the text in both p-element is bigger than normal).

Please help me out - is this a bug that needs to be reported?

like image 736
ironmouse Avatar asked Dec 12 '17 23:12

ironmouse


1 Answers

It seems this is a known problem how mobile browsers handle text sizing. See text-size-adjust. There are several options for this:

  1. <meta name="viewport" content="width=device-width, initial-scale=1">
  2. Working with the experimental property
  3. Setting a min-height of 1px or max-height of 99999. It seems that this will break layout on some mobile devices. (See post: Chrome on android resizes font)
like image 73
morpheus05 Avatar answered Sep 29 '22 18:09

morpheus05