Solved

Resize image based on the TD width

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Output to HTML in powershell 3 37
custom authorization on controller action and HTML in asp.net mvc 1 42
Mobile apps - web/native or hybrid? 1 63
Ajax on ASP 2 31
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 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 code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

679 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