I recently started to read the book called “Responsive Web Design” and I like the techniques used by the author but for some reason what I do doesn’t work on the iPhone, ok let me rephrase this it works but not like it should.
This is what I’m doing…
I have a simple html page and an external style sheet where I’m using @media queries to resize the content something like this…
/MOBILE/ @media only screen and (max-device-width:480px) { #page-wrap {
width:400px;
background-color:green;
margin:10px auto;
}
}
the code above does work, it actually resizes the page-wrap but when viewed on the iPhone it looks small, in other words it doesn’t fill the whole screen (no problems when viewed on a computer).
Any idea what am I doing wrong? Why it doesn’t actually fill the whole screen on the iPhone?
I know I could use the viewport meta tag but I want to use @media queries if possible.
I changed the width to use percentages and tried different percentage (100%, 90%, 33.333%) and the page changes to the percentage specified, with 100% it basically renders the page at 980px which I believe is the iPhone’s default, when use other percentage like 33% it basically leaves white spaces on the sides it doesn’t zoom to take the whole space it uses 33% of the 980px.
Current Code:
/iPHONE/ @media
only screen and (max-device-width: 480px) { #page-wrap {
width:33%;
background-color:green;
margin:10px auto;
}
}
It looks like it recognizes the iPhone’s screen size and changes accordingly but it doesn’t fill the whole screen, which defeats the purpose of having different widths.
I’m a little confused.
Have someone from here have done this before, if yes, can you show me your techniques?
The only thing i see wrong is you have no META tag that sets the default viewport for mobile devices, see what happens when you add the following to the <head> tags.