How to use SVG Sprite Sheet as CSS background-image while maintaining aspect ratio and scalability

前端 未结 2 717
不思量自难忘°
不思量自难忘° 2020-12-13 14:28

TL;DR: I want to use several icons tiled in an SVG sprite sheet as CSS background-images, which maintain their aspect ratio and automatically scale to fill the parent elemen

2条回答
  •  一生所求
    2020-12-13 15:08

    Basically, I want to know if there's an easier way to define the cells in the spritesheet and simplify the CSS I use to tell each div which icon to display from the spritesheet.

    No, you can't do it easier.

    Try this article

    Then, there's the problem of scaling. With this setup, the SVG scales to the appropriate size to be drawn on-screen, but if I decide to zoom using my browser's zoom, it pixelates. This is not how SVG is supposed to work.

    In Chromium 18 it looks pretty fine - no pixelations at all.

    In my test browsers list (FF3.6 Opera 9.2 IE6) I didn't see what I saw in Chromium

    And about IE9, maybe problem in engine

提交回复
热议问题