Is it possible to use CSS sprites for "foreground" images - i.e. images that users are supposed to click on and interact with and maybe even print?
Instead of using the CSS background-image property, instead you'd use... what?
Thanks!
~S
Is it possible to use CSS sprites for "foreground" images - i.e. images that users are supposed to click on and interact with and maybe even print?
Instead of using the CSS background-image property, instead you'd use... what?
Thanks!
~S
You can use a standard <img />
tag and put it in a container (like a <div />
) with a limited height/width. Then use relative positioning or negative margins to control the position of the image.
I outlined this technique in a blog post regarding using CSS sprites with <input type="image" />
You can do this, but you have to use background images for sprites as you have to be able to set position. This can be used for links or whatever you want. Look at Googles sprite, they use it for there buttons on iGoogle: http://img0.gmodules.com/ig/images/v2/sprite0_classic.gif
You can do this with less CSS like this:
.myClass { background: url(../Images/Sprite.png) no-repeat;
height: 20px;
width: 40px;
background-position: -40px 0;
display: block; }
.myClass:hover { background-position: -40px -20px; }
Whatever has the class class="myClass"
will have just the image in it, nothing else. This can be a <a>
an <input>
or a normal <div>
, whatever you want.
It's a background image...but it's the element you're looking at, nothing's in front of that background. Just because you're using background-image
for the property doesn't mean it's not a foreground element...like a button you can click on. You can do that like this:
<input type="button" class="myClass" />