Solved

Images not scaling properly

Posted on 2006-06-29
3
633 Views
Last Modified: 2008-03-17
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
Comment
Question by:skacore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
mshogren earned 500 total points
ID: 17013778
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
 
LVL 1

Author Comment

by:skacore
ID: 17052858
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
 
LVL 1

Author Comment

by:skacore
ID: 17053227
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question