We know how to use CSS to show only part of an image within a div (i.e., image sprites), but the image has to be a background image.
We know how to use CSS to scale an image, but the image has to be an IMG.
Does anyone know of a way to scale and image and show only part of it?
For example, I want to:
- show pixels (15,15) through (100,100), and
- scale it up by 200%.
The first I can do by making in a background image. The second I can do by making it a foreground image. But so far, I have not ascertained how to do both. Is it even possible using only CSS/HTML?
You could scale the image just as you would normally. Then, use a container div to crop the image. To set where the crop rectangle goes, use
position: relativeon the image (not the containing div). Here’s an example using stackoverflow’s logo: