从单个图像获取图标 [英] Get icon from single png image

查看:107
本文介绍了从单个图像获取图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到这么多次,直到现在,但我从来没有使用过自己。可以有人解释如何从这个单一的png图像获得特定的图标图片,例如我用红色...选择的图标使用css

I have seen this so many times until now, but I never used myself. Can somebody explain how you can get specific icon picture from this single png image, for example the icons i selected with red ... using css

推荐答案

被称为 CSS sprites 。它用于减少http请求。基本上所有图标都放在一个画布上,用作 background-image 属性,稍后使用CSS background-position 属性,例如

That is called CSS sprites. It is used to cut down the http requests. Basically all icons are placed on a single canvas and are used as background-image property and later they are mapped using CSS background-position property, so for example

.icon1 {
   background-image: url('YOUR_URL_HERE');
   background-position: 10px 10px; /* X and Y */
   height: 30px;
   width: 30px;
}

演示

因此,您只需为元素定义一个固定的高度/宽度,然后使用 background-position 属性。因此,如果您在一个页面上有100个小图标图像,它将向服务器发出100个请求,从而提高性能,使用CSS Sprite。

So inshort just define a fix height/width to your element, and than map the canvas using background-position property. Hence, if you have 100 small icon images on a page, it will make 100 requests to the server, thus to increase the performance, CSS Sprites are used.

这篇关于从单个图像获取图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆