Combine images using sprites
CSS Sprites is an old but still widely used technique, used for a long time on low memory consoles to store large amounts of images and information.
Always use CSS Sprites wherever you can. If you have a lot of icons, if you have a lot of decorative images and etc ... Join them and form a sprite of images that can be used throughout the site. This decreases the amount of requests the browser will make during the user's browsing.
When we use a lot of small images and the browser needs to make these requests together, there is a collection of tasks called request overhead .
I know that working with sprites gives work to maintain and mostly create the initial sprite. So you can use services to do this work for you. SpriteMe is one of them.
What slows down your site?
It is not only the weight of the files that interferes with the upload performance of your page, every time we upload a file we make a request to the server to transfer the file to the user's browser, the number of requests can and does interfere with site performance. And it's exactly about those server requests that the CSS Sprite will work.
What is CSS Sprite?
CSS Sprite is a technique where we place several images that we use in CSS in a single file, and position this file according to our needs using the background- of the CSS, property that makes use of mathematical coordinates similar to the (x, y) Cartesian plane.
Advantages:
-
A single request instead of several.
-
Loads the file only once and caches, so the rest
pages do not need to load it.
How to Use
First we need to build our file, and for this we must pay attention to a very important detail, if the HTML elements have rectangular format , we must pay attention to the positioning of the images inside the sprite to avoid them being shown pieces of images that would not come from that piece of the site.
What we should not do when positioning our images in the Sprite.
TherightwaytoworkonpositioningyourimagesintheSprite.
Now that we have our file set up, we'll use the background-position property to position it as shown below:
background-positionworkswith2parameters:backgroundpositioninXandbackgroundpositioninY,wherebothXcanbedeterminedasLeft,CenterorRight,andYcanbedeterminedasTop,Center,orBottom.BothXandYcanbedeterminedbynumericvaluestoo,wherewemustalwaysremembertoinformtheunitofmeasurethatweareusing.Wewillnowseewhatthesyntaxofthispropertyis:
Seletor{background-position:PosiçãoXPosiçãoY;}
Orwecanalsousereducedsyntax:
Seletor{background:corurl(pathdaimagem)posiçãoXposiçãoYrepetição;
ZKDESIGN
TABLELESS