css background position icons code example

Example: css image sprites

/******************** How to use image sprites? ************************/
/* For this, you need to position the image so that only a segment of it 
is revealed. This technique also allows you to zoom in on parts of the 
image */

<html>
  <head>
    <meta charset="UTF-8" />
    <title> Title </title>
    <style>

      #window_1 {
        height: 120px;
        width: 117px;
        background: url("image_path") 0px 0px; /* coordinates of the upper left point: x = 0 and y = 0 */
      }

      #window_2 {
        height: 150px;
        width: 100px;
        background: url("image_path") -300px -200px; /* coordinates of the upper left point: x = -300 and y = -200 (we use negative numbers) */
      }

    </style>
  </head>
  <body>

    <div id="window_1"></div>
    <div id="window_2"></div>

  </body>
</html>

Tags:

Css Example