Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML page doesn't fit mobile device screen

Tags:

html

css

mobile

Here is my HTML :

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no">
    <title>Test</title>
    <style type="text/css">
        body {
            font-size: 40px;
        }

        .screen {
            font-size: 0.5em;
            margin: 0;
            background-color: red;
            position: absolute;
            width: 8em;
            height: 19em;
            left: 0;
            top: 0;
        }

        .screen .main {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div class="screen">
        <div class="main">Ut enim benefici liberalesque sumus, non ut exigamus gratiam (neque enim beneficium faeneramur sed natura propensi ad liberalitatem sumus), sic amicitiam non spe mercedis adducti sed quod omnis eius fructus in ipso amore inest, expetendam putamus.</div>
    </div>
</body>
</html>

Although my meta tag for the viewport scaled to device-width, this page doesn't fit the screen : there are still white borders (on my Galaxy S3). I want it to be totally red.

What do I have to do to make this page fit totally my screen ? (and most devices' screens)

I'm a total newbie in mobile development, thank you

like image 570
Harkonnen Avatar asked Jan 16 '14 13:01

Harkonnen


People also ask

How do I make HTML screen fit on mobile?

So it is important to format a page to match the mobile screen's width in device-independent pixels. The “meta viewport” tag included in the <head> of the HTML document addresses this requirement. The meta viewport value as shown above helps format the entire HTML page and render the content to match any screen size.

How do I make the Web page fit my phone screen?

* Tap the menu button and choose Settings from the list. * Tap on the option Advanced. * Find the Auto-fit pages – Format Web pages to fit the screen option and make sure that this is checked. Thats it!


2 Answers

in addition to BenM's answer, set this in your css to remove the default style from browsers

html, body {
     font-size: 40px;      
     margin:0; /* remove default margin */
     padding:0; /* remove default padding */
     width:100%; /* take full browser width */
     height:100%; /* take full browser height*/
}

so complete css should :

  .screen {
                font-size: 0.5em;
                margin: 0;
                background-color: red;
                position: absolute;
                width: 100% /* BenM mentioned this in answer*/
                height: 100%; /* take full browser height */
                left: 0;
                top: 0;
            }

  .screen .main {
                width: 100%; /* <--now this takes full browser dimension  */
                height: 100%; /* <--now this takes full browser dimension  */
            }
like image 92
NoobEditor Avatar answered Oct 26 '22 17:10

NoobEditor


Try this

body {
margin:0;
padding:0;
}
like image 40
Surjith S M Avatar answered Oct 26 '22 18:10

Surjith S M