Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobile website html element too wide

Tags:

css

width

mobile

I'm designing a mobile version of my website, which should be like a mobile application.

The problem is that there is a strange width to my html element in my mobile browser. I have tried setting body and html to width:480px; and the content is 480px but even then there is a lot of whitespace next to the content (estimated at about 300px). The effect of this is also that the website is not zoomed to the content but to the content + the whitespace and you first have to zoom in to properly use the website.

Ofcourse I want to use width:100%; so it renders well on different screen sizes.

Does anyone know what's going on or how to fix it?

Edit The html code is just straightforward xhtml transitional, nothing special. In the css I have:

body, html {
width:480px !important;}

But if I would not set a width to those it should work right? I also don't set a width for any other elements (other than like buttons 100px and things like that) and if I view the mobile version on my computer no elements seem to be wider than the body.

like image 937
Thomas Avatar asked Apr 07 '11 13:04

Thomas


People also ask

Why my HTML page is too wide?

The problem is that everything has position:absolute; . This means that everything is positioned relative to the upper left hand corner of the page. One way you could eliminate this is to set a width and center the main div using something like margin:0 auto; .

How do I reduce the width of a HTML page?

Enclosing the content in a div that has the CSS width property set to 1000px will work across browsers. However, consider using 960 pixels instead of 1000. It is a reliable standard that works on most devices down to a 1024 pixel display width including space for scroll bars and such.


1 Answers

Have you add the viewport meta tag ?

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
like image 139
Yoann Avatar answered Oct 01 '22 17:10

Yoann