Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What CSS code do I use to get my webpage to fill the screen on a the iPhone or Android?

I have the HTML code below. I have set the body's width to 640px which is close to what the iPhone's resolution is. However, when I view the webpage on either an iPhone or an Android, it shows up just like it would in my web browser - only taking up part of the screen. The text is so small it's not usable.

What CSS code do I use so that the text stays normal in desktop browsers, but fills the screen on a mobile device? I read some things about using device-width properties but I can't get those to work either. What am I doing wrong?

Note I'm not trying to get the red border to stretch all the way across the screen (eg: body:width100%). I just don't understand why the iPhone is not zooming into an area that is set to the same resolution it is supposed to have.

HTML Code:

<style>
    body{ width:640px; border: 1px solid red; }
</style>

</head>
<body>
Hello World
</body>
</html>

Actual Output:

actual1.jpg

Desired Output:

desired.jpg

like image 453
cwd Avatar asked Feb 03 '26 15:02

cwd


2 Answers

Put this in your head tag:

<meta name="viewport" content="width=480">
like image 179
Diego Torres Avatar answered Feb 05 '26 05:02

Diego Torres


To make the iPhone zoom in on the page, you can use the viewport meta tag. You can set a scale of 1.0 to make Mobile Safari zoom in on your content exactly, no matter it's actual size.

Here's some documentation on different ways of setting the viewport: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html

like image 45
Brid Avatar answered Feb 05 '26 06:02

Brid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!