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>
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.
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!
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.
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 :)
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With