Home > Web Front-end > CSS Tutorial > How Can I Scale a Cropped Image Within a CSS Sprite?

How Can I Scale a Cropped Image Within a CSS Sprite?

Mary-Kate Olsen
Release: 2024-12-08 06:18:15
Original
287 people have browsed it

How Can I Scale a Cropped Image Within a CSS Sprite?

Scale a Cropped Image in a CSS Sprite

In the article "Create CSS Sprites to Enhance Your Page Performance," it explains how to crop a smaller image from a larger one. However, you may encounter a scenario where you need to scale the cropped image before incorporating it into your design. This can be achieved using various techniques.

Background-Size Method (IE9 , Modern Browsers)

Use the background-size property to specify the desired scaled size of the cropped image. For instance, if you want to double the image size, use the value 150% 150%.

background-size: 150% 150%;
Copy after login

Zoom and Transform Scaling

For cross-browser compatibility, combine zoom for WebKit/Blink/IE browsers with transform:scale for Mozilla and older Opera browsers.

[class^="icon-"] {
  display: inline-block;
  background: url('../img/icons/icons.png') no-repeat;
  width: 64px;
  height: 51px;
  overflow: hidden;
  zoom: 0.5;
  /* Mozilla support */
  -moz-transform: scale(0.5);
  -moz-transform-origin: 0 0;
}

.icon-big {
  zoom: 0.60;
  /* Mozilla support */
  -moz-transform: scale(0.60);
  -moz-transform-origin: 0 0;
}

.icon-small {
  zoom: 0.29;
  /* Mozilla support */
  -moz-transform: scale(0.29);
  -moz-transform-origin: 0 0;
}
Copy after login

This method allows you to scale specific cropped regions of the sprite without affecting other segments. You can adjust the zoom and scale values to achieve the desired sizes.

The above is the detailed content of How Can I Scale a Cropped Image Within a CSS Sprite?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template