Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Resize image based on the TD width

Posted on 2004-03-30
7
Medium Priority
?
808 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 500 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:Andy
Andy earned 500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

885 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