Solved

Images not scaling properly

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Display multiple images in the row in PHP 11 69
spacing 5 31
Setting Up a Responsive Form 24 41
HTML CSS 7 19
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 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

24 Experts available now in Live!

Get 1:1 Help Now