Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Images not scaling properly

Posted on 2006-06-29
3
Medium Priority
?
634 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

719 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