Solved

Images not scaling properly

Posted on 2006-06-29
3
630 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i create a customized Login page based on Wordpress ? 8 36
Wrapper for APPs 9 76
Problem with spacing columns on a row in a table 10 23
Scroll 5 news at a time. 4 25
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now