且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单个图像文件存储页面上的所有小图像

更新时间:2023-11-09 18:30:52

基本上,您使用单个图像作为背景图像,但将其移动(向左和向上)您要显示的图像的偏移。例如。显示锤子图标:

Basically you use your single image as the background image, but move it off (to the left and up) by the offset of the image you want to display. E.g. to display the hammer icon:

.hammer
{
  background: transparent url(myIcons.jpg) -50px -50px no-repeat;
}

但据我所知,你必须确保使用背景图片具有正确的大小(例如32x32像素)。

But as far as I know, you have to make sure that the element that's using the background image has the correct size (e.g. 32x32 px).

搜索CSS Sprites会为您提供更多信息。

A search for CSS Sprites will give you more information.