Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 812
  • Last Modified:

Resize image based on the TD width

I want to resize an image based on the TD width.Could you please help me out doing this
0
BLN2004
Asked:
BLN2004
  • 2
  • 2
2 Solutions
 
dgelinasCommented:
sure,

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



  <td id='td1'>
  <img id='img1' src='/images/whatever.gif'>
0
 
dgelinasCommented:
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
 
AndyCommented:
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
 
brunoCommented:

 http:Q_20937172.html#10713270


script tags were a tad backwards...  ;-)
0
 
brunoCommented:
no points needed for me here - was just pointing out an error in the code.  thanks anyway.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now