Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get icon from single png image

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

enter image description here

like image 375
David Dury Avatar asked Aug 12 '13 06:08

David Dury


People also ask

Can a PNG be used as an icon?

Icon used by browsers to identify a webpage or site. While all browsers support the . ico format, the PNG format can be preferable.

Can I use PNG for Icon Windows 10?

Windows uses ICO files for its icons. Thus, you'll need to convert images from PNG (or other image formats) before you use them as icons. ConvertICO offers an easy way to do this. You can upload up to 50 PNG images at once to convert them into the ICO format.


2 Answers

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;
}

Demo

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.

like image 58
Mr. Alien Avatar answered Oct 26 '22 16:10

Mr. Alien


  1. Set a fixed (in pixels) height and width on an element
  2. Set the image as the background-image
  3. Adjust background-position so the part of the image you want to be visible is in view
like image 5
Quentin Avatar answered Oct 26 '22 16:10

Quentin