Solved

Resize image based on the TD width

Posted on 2004-03-30
7
790 Views
Last Modified: 2012-06-27
I want to resize an image based on the TD width.Could you please help me out doing this
0
Comment
Question by:BLN2004
  • 2
  • 2
7 Comments
 
LVL 6

Expert Comment

by:dgelinas
ID: 10713270
sure,

</script>
function resizeImage() {
  document.getElementById('img1').width =  document.getElementById('td1').offsetWidth
}
<script>



  <td id='td1'>
  <img id='img1' src='/images/whatever.gif'>
0
 
LVL 6

Accepted Solution

by:
dgelinas earned 125 total points
ID: 10713550
better yet here's a working test I used.. obviously you won't have my image but you can replace it with yours

<html>
<head>
<script language="javascript" type="text/javascript">
function resizeImage() {
  document.getElementById('img1').width =  document.getElementById('td1').offsetWidth
}
</script>

</head>

<body onLoad="resizeImage()">


<table width="183"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id='td1'><img id='img1' src="logo2.gif" width="5" height="50"></td>
  </tr>
  <tr>
    <td></td>
  </tr>
</table>  

</body>
</html>
0
 
LVL 6

Assisted Solution

by:Reapz
Reapz earned 125 total points
ID: 10713746
Or... If you simply mean that you want the image to resize as the browser window is resized then place the image inside the cell you want and then set the width and height of the image to 100%. The width of the image will then be adjusted to fit the cell and the height will be adjusted accordingly. As you resize your browser window the size of the image will be adjusted too.

As with any on the fly resizing the quality won't great though.
0
 
LVL 18

Expert Comment

by:bruno
ID: 10720251

 http:Q_20937172.html#10713270


script tags were a tad backwards...  ;-)
0
 
LVL 18

Expert Comment

by:bruno
ID: 11026102
no points needed for me here - was just pointing out an error in the code.  thanks anyway.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
How to change the link of an image using md5 in php ? 3 47
innerHTML 7 34
Show Ruler in Outlook 2010 STILL NOT SHOWING! 4 23
Javascript 2 20
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

809 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