In this article, http://css-tricks.com/css-sprites/, it talks about how can I crop off a smaller image from 1 bigger image. Can you please tell me if it is possible/how I can crop off a smaller image and then scale the cropped off region before I lay it out?
Here is an example from that article:
A
{
background-image: url(http://www.jaredhirsch.com/coolrunnings/public_images/3deb155981/spriteme1.png);
background-position: -10px -56px;
}
I would like to know how can I scale that image after I crop it from from spriteme1.png
Here is the URL of the example: http://css-tricks.com/examples/CSS-Sprites/Example1After/
So I would like to know if I can make the icons next to Item1,2,3,4 smaller?
Easy... Using two copies of same image with different scale on the sprite's sheet. Set the Coords and size on the app's logic.
You could use background-size, as its supported by most browsers (but not all http://caniuse.com/#search=background-size)
Or
You can use a combo of zoom for webkit/ie and transform:scale for Firefox(-moz-) and Opera(-o-) for cross-browser desktop & mobile
Use
transform: scale(...);
and add matchingmargin: -...px
to compensate free space from scaling. (you can use* {outline: 1px solid}
to see element boundaries).Old post, but here's what I did using
background-size:cover;
(hat tip to @Ceylan Pamir)...EXAMPLE USAGE
Horizontal circle flipper (hover on front side image, flips to back with different image).
EXAMPLE SPRITE
480px x 240px
EXAMPLE FINAL SIZE
Single image @ 120px x 120px
GENERIC CODE
.front {width:120px; height:120px; background:url(http://www.example.com/images/image_240x240.png); background-size:cover; background-repeat:no-repeat; background-position:0px 0px;}
.back {width:120px; height:120px; background:url(http://www.example.com/images/image_240x240.png); background-size:cover; background-repeat:no-repeat; background-position:-120px 0px;}
ABBREVIATED CASE FIDDLE
http://jsfiddle.net/zuhloobie/133esq63/2/
Well I think found a simpler solution for scaling images : example - lets say there is an image with 3 equal sized sprites which you would want to use, use CSS to scale the image
and then specify the custom height and width that needs to be applied to your html element eg:
A sample code would look something like this :
im pretty new to css ,and styling is not my best area this could be a wrong way of doing it.. but it worked for me in Firefox/Chrome/Explorer 10 ,hope it works in older versions too..
Set the width and height to wrapper element of the sprite image. Use this css.