Hi guys, first off I apologize if this wasn't posted in the correct forums.
Well, I am designing my first mobile website. I am trying to make the width adjust to the individual screen size 100%. My main background is just fine obviously, however both my header and content DIV's will not stretch out, according to the Feature Phone preview (in the dropdown of Multiscreen preview) and in Device Central. However, the strange thing is that if I view it in Multiscreen Preview or in Firefox, it's just fine. I also don't see a problem within my code, where I have set the width of both to 100%. I am not sure what is going on with this.
| #header { | ||
| background:#CCC; | ||
| text-align:center; | ||
| width:100%; | ||
| } | ||
| #content { | ||
| background-image:url(images/bg.jpg); | ||
| background-repeat:repeat-x; | ||
| background-color:#6392C0; | ||
| width:100%; | ||
| text-align:center; | ||
| } |
This it my HTML code for these DIV's.
Here is the image viewed in the Feature Phone. It also looks the same in Device Central.
And here it is in Multiscreen Preview. The width is fixed just fine in both this preview and in Firefox.
Any ideas? Thanks in advance!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Temperature</title>
<!-- Mobile -->
<link href="css/mtemp.css" rel="stylesheet" type="text/css" media="only screen and (max-width:480px)" />
</head>
<style type="text/css">
* {
margin:0;
padding:0;
font-family: Helvetica, sans-serif;
-webkit-text-size-adjust:none;
}
#header {
background:#CCC;
text-align:center;
width:100%;
}
#content {
background-image:url(images/bg.jpg);
background-repeat:repeat-x;
background-color:#6392C0;
width:100%;
text-align:center;
}
#content img {
margin:30px;
}
</style>
<body bgcolor="#6591C2">
<div id="header">
<h2>Header</h2>
</div>
<div id="content">
<p><img src="images/box.png" width="206" height="208" /></p>
</div>
</div>
</body>
</html>The problem is your image margin. Your total margin width plus image width exceeds the view width. Change your CSS to the below:
#content img {
margin:30px;
margin:30px auto;/* 30px margin top/bottom, auto margin left/right*/
display:block;
}
And also remove the additional closing </div> as OS has mentioned.
Good spot 266px as opposed to 240px.
I guess to preserve the 30px either side of the image IF its critical set the:
#content img {
max-width: 100%;
margin: 30px;
}
and delete the width and height. That will give you a scalable image, which may look better on mobile.
<p><img src="images/box.png"/></p>
North America
Europe, Middle East and Africa
Asia Pacific