Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resize an image in 'a href' tag link

Tags:

html

image

resize

looking at the code below, i can show an image with a smaller size

<a href="images/image.jpg"><img src="images/image.jpg" width="300" height="214" border="0"></a>

but what if i want the href link to show the image with a smaller size as well. so lets say the original image.jpg is 1500x1200 and in the link i want to show it 800x600.

is there anyway to do something like this:

<a href="images/image.jpg" width="800" height="600"><img src="images/image.jpg" width="300" height="214" border="0"></a>
like image 236
leora Avatar asked Oct 15 '09 13:10

leora


People also ask

How do I resize a linked image in HTML?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.

What does href =# do?

Definition and Usage The href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink. Tip: You can use href="#top" or href="#" to link to the top of the current page!

How do I link a href to an image?

To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image. With that, also add the height and width.


2 Answers

If I understand correctly, you want to control the size of the image that is the target of the href, using attributes of the a tag?

You can't do that. Your best bet (for controlling the size from the source of the link) is to serve your images using a server-side script which accepts size parameters in a querystring. Like image.php?img=image.jpg&w=800&h=600.

But that's a whole other question and would be out of scope for me to go into detail here.

Of course if you want to just change the image to a particular size, just resize the actual image and upload it again :)

like image 60
Ben James Avatar answered Sep 24 '22 09:09

Ben James


Here is a funny solution:

<a href="javascript:document.getElementsByTagName('body')[0].innerHTML='<img src=images/image.jpg width=800 height=600>'"><img src="images/image.jpg" width="300" height="214" border="0"></a>

Though personally I would not recommend it, it works. :)

like image 24
treznik Avatar answered Sep 25 '22 09:09

treznik