Forum Moderators: not2easy

Message Too Old, No Replies

CSS image scaling

CSS will not scale an image as intended

         

Pluckerpluck

4:09 pm on Jan 14, 2009 (gmt 0)

10+ Year Member



I can't work out why this doesn't work. I have been trying to make a fully scalable website and was try to add vertical scaling. I also needed to make an image (of my header) to scale as well.

So I set my page to 100% height and then made a table at 70%. I then divided the parts of the table (header information and footer) equaling 100%. It all seems to work at this point and everything scales as my browser changes (I am testing on Firefox 3).

However, when I add an [img] tag into the header and set its size to 100% width and height, the header no longer scales. It stays at a set hieght that doesn't change when I resize my browser. I cannot see why.

Can anybody help please.

CSS:
html, body
{
height: 100%;
}

.wrap
{
height:70%;
}

.header
{
height:10%;

}
.information
{
height:60%;
}
.footer
{
height:30%;
}

.images
{
height:100%;
width:100%;
}

HTML:
<table class="wrap">
<tr class="header">
<td colspan="2" class="header">
<img src="images/header2.png" class="images"/> </td>
</tr>
<tr class="information">
<td class="links">
Middle</td>
</tr>
<tr class="footer">
<td colspan="2" class="footer">
Botton</td>
</tr>
</table>

I'm using
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

[edited by: Pluckerpluck at 4:12 pm (utc) on Jan. 14, 2009]

Wlauzon

4:25 pm on Jan 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot scale images with CSS.

simonuk

4:58 pm on Jan 14, 2009 (gmt 0)

10+ Year Member



You can use em instead of pixels to scale the height but you would have to specify this in classes for each image. If I had to go down this route I would make sure the images used were always one of a handful of widths and heights to make managing the site easier.

Pluckerpluck

5:00 pm on Jan 14, 2009 (gmt 0)

10+ Year Member



If I were to change the percentage size of the image manually it would scale normally. So why wouldn't it scale to the size of the cell is it in.

Wlauzon

2:03 am on Jan 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, there are several issues with what you are trying to do.

Technically, you can scale an image with CSS - but only in one direction, the way you are trying to do it. You can scale them using em's, but there are issues doing that. You can scale images also (sort of) with HTML. You often end up with some ugly looking images though either way. Some images - esp jpg - simply do not degrade well when squished that way, because you are not really resizing the image, just what shows up on the viewers screen.

The problem either way is that you have not reduced the image size, only what shows up. If you scale 2000px image down to 100px, when anyone downloads that page they are downloading the full 2000px image.

Here is a way to do, but it is generally bad practice to make drastic changes in size this way.

[w3.org...]