Solved

Resize image based on the TD width

Posted on 2004-03-30
7
781 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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…

759 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