I have two reasons I want to use csssprites for submit buttons :
- I have dynamically created button, which in the future might be localized
- I want just 1 HTTP request even if I have 5 buttons on the page
The problem is that I want to avoid javascript for buttons, and therefore I need to use an input
field of type image
. I can set the background image on this field just as i would for any csssprite.
The problem is that I found I had to set the image source to an empty pixel or else I get a broken image icon.
With that said, this is the best solution I have come up with :
<style>
.csssprite_cat {
background-image:url(http://www.mrfreefree.com/images/speciali/211/funny_cat_50.jpg); width: 50px;
height: 50px;
}
</style>
<input type=image src="http://www.grasse-ac.com/gif/no_pixel.gif" class="csssprite_cat">
<input type=image class="csssprite_cat">
(You can just load this file directly into a browser - i am borrowing images from a random site).
It works kind of OK, but I have to use our good old friend pixel.gif. Very nostalgic!
There probably isn't a better way without javascript, unless there is a way in css to hide the broken image text and icon.