Creating clickable background images using CSS

From Joomla! Documentation

This tutorial is for Joomla! CMS Version(s)

What this is about

Okay, lets say you have a mostly finished template, with a typical corporate layout: A header, a content body area, and a footer. In the header you have placed a background image with a big company logo and some nice artwork next to it, with some dynamic content on top of the bottom right corner of the background image. Suddenly you realise that a click on the company logo part of that background image should bring the user back to the homepage. Usually you would cut out the image and place it directly inside the link. However you don't have enough time to cut up the image and re-work your template accordingly, so what you need is a quick-fix.

Note: Legitimate uses for the following technique might include things like tab-interfaces where the tabs should be able to stretch and still have a background image, or blog-skins which only differ in CSS.

How to do it

First: You can't just copy the #header-content div, position it over the logo, make the content invisible and enclose it in an anchor-tag. That would be broken HTML, because you can't place block-level elements like div inside anchor tags.

You can however enclose a stretched, one-pixel, transparent GIF image in anchor tags (as per example one) if you have to support old browsers. Otherwise you can simply turn the anchor itself into an inline-block using CSS 2.1 (as per example two).