简介
这种技巧的名称叫做CSS Sprite,基本原理就是利用CSS中图片background系列的background-image、background-repeat、background-position等属性实现。通过这种方式达到图片显示加速的关键,不是降低重量,而是减少个数。在通常情况下一张图片的传输时间,通常远小于请求等待的时间。

PS:特别制作了三个CSS Sprites实例演示,感兴趣的朋友可以看一看。

实例
比如google.cn现在首页的底部导航也是用这个方式实现的。
所用图片为:http://www.ccvita.com/wp-content/uploads/demo/css/google.gif
效果:http://www.google.cn

 

代码
从网上找了好几个演示,大家可以看下面地址的演示:CSS Sprites实例演示
效果一:纵向背景图

 

最大化
最小化

效果二:横向背景图

 

颜色
链接

效果三:平滑投票

 

满分5.0, width:70px

  • Current rating: 4.7 (3 votes)
  • 1
  • 2
  • 3
  • 4
  • 5

当前2.5, width:35px

  • Current rating: 4.7 (3 votes)
  • 1
  • 2
  • 3
  • 4
  • 5

资料
本文在写作的过程中严重参考了如下文章:
CSS Sprites的实现
http://realazy.org/blog/2007/10/08/css-sprites/
加速图片显示
http://www.blueidea.com/tech/site/2007/4750.asp
利用CSS技巧减小HTTP请求
http://www.ccvita.com/322.html
Yahoo的YShow网站优化中的34条规则
http://developer.yahoo.com/performance/
CSS Sprites: Image Slicing’s Kiss of Death
http://alistapart.com/articles/sprites

arrow
arrow
    全站熱搜

    Felix 發表在 痞客邦 留言(0) 人氣()