CSS Sprites - not only for background images?

后端 未结 5 543
-上瘾入骨i
-上瘾入骨i 2021-01-02 04:00

Is it possible to use CSS sprites for \"foreground\" images -- i.e. images that users are supposed to click on and interact with and maybe even print?

Instead of usi

5条回答
  •  难免孤独
    2021-01-02 04:44

    I have solved this problem using img tags and using the object-fit and object-position properties in my css. Here's a sample of the html and css I used:-

    HTML

    
    

    CSS

    .sprite-icon {
      height: 20px;
      width: 20px;
      object-fit: none;
    }
    
    .sprite-icon-1 {
      object-position: 0 0;
    }
    
    .sprite-icon-2 {
      object-position: -20px 0;
    }
    

    Obviously, you need to change the position and the size parameters according to the sprite you are using. For a full working example, check out this fiddle

提交回复
热议问题