CSS Sprites - not only for background images?

后端 未结 5 518
-上瘾入骨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条回答
  •  -上瘾入骨i
    2021-01-02 04:34

    One primary requirement that cannot be handled by background images is for ARIA. All ARIA requirements will reject the use of background images for meaningful, navigational, and other 'informative' uses that a screen reader must interpret on behalf of a user with a disability. Being able to swap out a background image css statement for an img tag and some ARIA tagging whenever necessary is a critical feature in the current regulated development environment.

    The answer to the original question is yes! It is possible to use the image that is displayed in a css background statement. But you must open the sprite image in an image editor and select out the portion that represents the sprite you want and save it as a separate image and reference it in an img tag.

    The challenge is that often, these situations arise in a pre-built control library. Finding and altering the code in the library that selects and displays the background image is a little difficult, changing out the code is hard!

提交回复
热议问题