Forum Moderators: not2easy
Here is my current code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
.yo a {
background: transparent url('color.png') no-repeat;
display: block;
width: 140px;
height: 136px;
}
.yo a:hover {
background-position: 136px 0;
}
<div class="yo">
<a href="#">
<img width="140" height="136" src="bw.png" title="Blah" />
</a>
</div>
What could possibly work is adding:
.yo a:hover img { visibility: hidden; } Which should remove the
bw.png on hover, so it will display the background image. You may need to remove your background position, I'm not sure what you're trying to achieve with it sitting 136px from the left edge of the anchor, which when given the image width of 140px, will mean you only get to see 4px worth of background image.
So I tweaked a bit, and this is the working code:
.yo a {
background: transparent url('bw.png') no-repeat;
display: block;
width: 140px;
height: 136px;
}
.yo a:hover {
background: transparent url('color.png') no-repeat;
}
<div class="yo">
<a href="#">
<img width="140" height="136" src="clear.gif" title="Blah" />
</a>
</div>
I replaced the picture in the <a> tags with a 1px clear gif image, the same size as my background images. This seems to work with the hover just fine.
My only problem now is that now my images are in a line down the page. I need them to be side by side. I tried changing display:block to display:inline, but when I do that the images don't appear correctly. I just get a small rectangle of the image cut-off at the bottom of the square where the image is supposed to be. Any thoughts on this?
Problem is, then the parent element that contains all these items will have no children that are in the natural document flow (floating removes it from that) so the parent element will have 0 height. This may not be a problem if there's nothing on them, but you may need to clear it if you had a background colour or anything like that on the parent element (
div.yo) [edited by: Setek at 12:29 pm (utc) on May 30, 2008]
Someone with a smaller screen resolution would have the actual link images going off the right side of the page. Same case scenario if the window was resized.