Forum Feature requests

Adding anchors to img elements

JohnClarke
I notice that the following:

<a href="http://www.google.com"><img src="mygooglelogo.gif" style="border: 1px solid red;"/></a> 


produces an image with an anchor only a fraction of the visible image size (the red box shows this). So, If I want to use an image like a link, I must tweek the anchor with a "height" attribute.

Would it be possible to (a) make anchors containing images assume the shape of the image? or (b) allow something like:

<img href="http://www.google.com" src="mygoogleogo.gif" />


or (c)

allow href be used in other elements like span,div,h1,h2? Perhaps this is invalid XHTML...

John Clarke
Cornerstone Systems Northwest Inc.

mikeday
Option (b) will work, if you do this:
img[href] {
    link: attr(href)
}

<img src="foo.png" href="http://www.example.com"/>

This is not valid XHTML, although it will be valid XHTML 2 in the future, as XHTML 2 will support the href attribute on all elements. :)

By the way, when you say that "the red box shows this", do you mean that the border does not fully surround the image? If the border is on the image itself, then it should surround the image. If the border is on the containing span, such as the <a> for example, then the image may go beyond the border. You can change this behaviour by applying "text-height: max-size" to the containing span, so that it stretches to fit the content within it.
JohnClarke
Michael, your suggestion works great. Thank you! -John

John Clarke
Cornerstone Systems Northwest Inc.