Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Images not scaling properly

I have an image that I would like to display as a background image on a page, and on top of it I have a div that contains the page contents.  In mozilla when I stretch or shrink my browser window, it distorts the image (does not maintain aspect ratio). In IE, the background maintains the aspect ratio.   I need it to NOT maintain aspect ratio (similar to Mozilla) in IE.

<div id="background_image"><img src="images/bg2.jpg" width="100%" height="100%" border="0" /></div>
<div id="content">
  I have page contents here
</div>
</div>

In IE it is not recognizing the "height=100%" parameter correctly.  If I make it height="1000px;"   it stretches the image.  I just want it to stretch with the size of the users browser.  

0
skacore
Asked:
skacore
  • 2
1 Solution
 
mshogrenCommented:
You need to specify the height of the containing elements like this:

<body width="100%" height="100%">
<div id="background_image" width="100%" height="100%"><img src="Sample.jpg" width="100%" height="100%" border="0" /></div>
<div id="content">
  I have page contents here
</div>
</div>
</body>


Note that this uses 100% of the screen size give or take margins and padding.  If you want to use 100% of the viewport you will need to use Javascript to dynamically resize the image.
0
 
skacoreAuthor Commented:
I applied these styles to the image and the body, but it still does not scale properly.  I want IE to distort the image, and not maintain aspect ratio, but it will only expand horizontally (not vertically).  I am using the styles that work on another site, but it is not scaling.  Works great in Firefox, but not in IE.  The test site I'm hitting works in IE as well as Mozilla (and has no javascript)

Any ideas what could be locking the aspect ratio?  Is this something that can be controlled serverside (through IIS), or is it just rendering HTML clientside?

I'm out of ideas, anything that could help would be appreciated. The CSS I'm applying to the above code is listed below


body {
margin: 0px;
padding: 0px;
background-color: #555656;
overflow: hidden;
}

#background_image {
position: absolute;
left: 0px;
top: 0px;
width:100%;
height:100%;
z-index: 1;
}

0
 
skacoreAuthor Commented:
I played around, and found the answer:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

will not allow for images to scale without maintaining aspect ratio.  ... thanks for all the help and suggestions
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now