Hey guys, I'm finishing my new site, but I've got a problem. One of the images on the site is inserted in the style sheet, and not in the HTML/PHP. And, I want that particular image to link somewhere (actually, I want it to link to my website). Here's a bit of the CSS: #container{ margin:0 auto 15px auto; width:700px; padding:10px; background:#ffffff url(images/front.png) bottom left no-repeat; color:#303030; border:20px solid #505050 url(border.png); } Code (markup): I want "front.png" to link to a website. How can I do that? Thanks!
http://codingforums.com/archive/index.php?t-65811.html There's a simple CSS solution. Insert a link into the parent container, taking note of it's dimensions, and insert a link with ' ' as the anchor text. Give the link CSS attributes to change it to a block level element with the same dimensions as the parent conainer. EG: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- #bgImg01 { background: #999999; height: 50px; width: 150px; border: 1px solid #333333; } #bgImg01 a { text-decoration: none; display: block; height: 50px; width: 150px; } --> </style> </head> <body> <div id="bgImg01"><a href="someLink.htm"> </a></div> </body> </html>
If you cannot change the HTML, you cannot make it a link. Just to be clear. Also, I usually advise people not to use character entities if they are writing XHTML. Not that it's ever "real" XHTML but we like to try as if it is, and since XML doesn't allow most HTML character entities, we try to stay strict by using hex-version ASCII (and in this case, an actual space will work). If the browser loses your whitespace, no problem-- the link, if turned into a block, will retain it's height and width so you'll still have your clickable area (I know cause I have it on my company's site... clickable background images).
What you could do is just make it the background of a h1 and link the h1, but position the text like -2000 left or something. I use that all the time for my websites.
There's no way to do it with CSS at this time, not with proper browser support anyway. You'll have to edit the HTML. If you want to link the background image, you'll have to introduce an anchor over the image and style that anchor's size to covert the width and height of the image. It's a bit tricky at first, but it works.