How do CSS sprites work?

后端 未结 5 903
迷失自我
迷失自我 2020-12-03 20:41

I have 3 different images and want to create a sprite using CSS. I understand that will reduce HTTP requests. However, I am totally new to this concept and have no idea as

5条回答
  •  离开以前
    2020-12-03 21:05

    Let's say you have button which changes its background image when it's moused-over. Mouseovers need to happen instantly to give good feedback to the user. If you just simply switched the image on the button, a browser might have to go to the server to fetch the image, which would spoil the effect. By using a CSS sprite, you have each image loaded and ready to go on the button instantly.

    Also, some browsers "flicker" when you switch images. CSS sprites avoid this flicker issue which can sometimes happen.

提交回复
热议问题