Here's my take on things.
View the source for comments.
(Posting jsbin code here for completeness' sake.)
Based on the assumption that you can't modify HTML, here's a couple of solutions:
EXAMPLE 1
Not using a sprite.
CSS:
.main_advert_1 {
width: 64px; /* Width of logo. */
height: 64px; /* Height of logo. */
background: url(http://drfatmaclinic.com/wp-content/uploads/2012/05/before-after_juvederm1-64x64.jpg) no-repeat;
}
.main_advert_1 a {
/* Now the <a> fills the parent container: */
width: 100%;
height: 100%;
display: block; /* Required for <a> to expand to fill parent. */
}
.main_advert_1 img { display: block; }
.main_advert_1 a:hover img { display: none; } /* Hide on hover. */
HTML:
<div class="main_advert_1">
<a href="#" target="_blank">
<img alt="Website" src="http://drfatmaclinic.com/wp-content/uploads/2012/06/before_after_restylane1-64x64.jpg">
</a>
</div> <!-- /.main_advert_1 -->
EXAMPLE 2:
Using a sprite.
CSS:
.main_advert_2 {
/* Width and height of logo/ad/whatever. */
width: 284px;
height: 284px;
}
.main_advert_2 img { display: none; } /* Just hide it so you can do stuff with the <a> only. */
.main_advert_2 a {
/* Random sprite found on web: */
background-image: url(https://dw1.s81c.com/developerworks/mydeveloperworks/blogs/waldensponderings/resource/BLOGS_UPLOADED_IMAGES/sel-tux_wizard.png);
background-repeat: no-repeat;
/* IBID: */
width: 100%;
height: 100%;
display: block; /* IBID */
}
.main_advert_2 a:hover { background-position: 0 -284px; } /* Position sprite on :hover. */
HTML:
<div class="main_advert_2">
<a href="#" target="_blank">
<img alt="Website" src="http://drfatmaclinic.com/wp-content/uploads/2012/06/before_after_restylane1-64x64.jpg">
</a>
</div> <!-- /.main_advert_2 -->
If you could edit the HTML, then you could remove the <img>
and your code would be a tad "cleaner".
Is that of any help?
EDIT #1
Here's a new version based on your comments.
CSS:
.main_advert {
/* Width and height of logo/ad/whatever. */
width: 728px;
height: 90px;
}
.main_advert img { display: none; } /* Just hide it so you can do stuff with the <a> only. */
.main_advert a {
/* Random sprite found on web: */
background-image: url(http://trickerygaming.net/tsf2/images/registeroof.png);
background-repeat: no-repeat;
/* IBID: */
width: 100%;
height: 100%;
display: block; /* IBID */
}
.main_advert a:hover { background-position: 0 -90px; } /* Position sprite on :hover. */
HTML:
<div class="main_advert">
<a target="_blank" href="#"><img border="0" src="./images/register.jpg" alt="Register"></a>
</div>
Better?
EDIT #2
Here's a version where I removed the <img>
and replaced it with text.
(View the HTML/CSS here.)
CSS:
.main_advert {
text-indent: -999em; /* This hides the "Register on our forums." text (see below). */
/* Width and height of logo/ad/whatever: */
width: 728px;
height: 90px;
margin: 0 auto; /* Centers this container inside parent. */
overflow: hidden; /* Hides indented text from above. */
}
.main_advert a {
/* Your image: */
background-image: url(http://trickerygaming.net/tsf2/images/registeroof.png);
background-repeat: no-repeat;
/* IBID: */
width: 100%;
height: 100%;
display: block; /* Allows <a> to fill parent. */
}
.main_advert a:hover { background-position: 0 -90px; } /* Position sprite on :hover. */
.main_advert a:active,
.main_advert a:focus { outline: none; } /* Removes ugly outline, on click, in some browsers. */
HTML:
<div class="main_advert">
<a target="_blank" href="#">Register on our forums.</a>
</div> <!-- /.main_advert -->
For a "sprite" technique, I like this approach the best.
Actually, if it were me, I'd probably try doing things with CSS3.
For CSS3 tools to give you ideas/inspiration, check out: