最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442

CssGaga教程:AutoSpritE的使用

日期:09-08    来源:中国设计秀    作者:cnwebshow.com

市面上有一些sprite生成器,要么是要人工调整图片位置,要么要拷贝粘贴代码,用起来总是觉得不够爽,cssGaga使用了不同的思路,希望能解放你的双手:) 使用时选中AutoSprite即可开启此功能,下面通过一个例子来说明: 比如HTML:LVS中国设计秀

<s class="i1"></s><s class="i2"></s><s class="i3"></s><s class="i4"></s><s class="i5"></s><s class="i6"></s>

css源文件:LVS中国设计秀

body{background-color:black;}
s{display:inline-block;width:16px;height:16px;overflow:hidden;background-repeat:no-repeat;}
.i1{background-image:url('slice/1.png');}
.i2{background-image:url('slice/2.png');}
.i3{background-image:url('slice/3.png');}
.i4{width:64px;height:64px;background-image:url('slice/4.png');}
.i5{background-image:url('slice/3.png');}
.i6{width:64px;height:64px;background-image:url('slice/6.gif');}
.i11{width:60px;height:60px;background-image:url('slice/1.jpg');}
.i12{width:60px;height:60px;background-image:url('slice/2.jpg');}
.i13{width:60px;height:60px;background-image:url('slice/3.jpg');}
.i14{width:60px;height:60px;background-image:url('slice/4.jpg');}

cssGaga生成后:LVS中国设计秀

body{background-color:black}
s{display:inline-block;width:16px;height:16px;overflow:hidden;background-repeat:no-repeat}
.i1{background-image:url(sprite/style.png);background-position:-128px 0}
.i2{background-image:url(sprite/style.png);background-position:-128px -16px}
.i3{background-image:url(sprite/style.png);background-position:-128px -32px}
.i4{width:64px;height:64px;background-image:url(sprite/style.png);background-position:0 0}
.i5{background-image:url(sprite/style.png);background-position:-128px -32px}
.i6{width:64px;height:64px;background-image:url(sprite/style.png);background-position:-64px 0}
.i11{width:60px;height:60px;background-image:url(sprite/style.jpg);background-position:0 0}
.i12{width:60px;height:60px;background-image:url(sprite/style.jpg);background-position:-60px 0}
.i13{width:60px;height:60px;background-image:url(sprite/style.jpg);background-position:-120px 0}
.i14{width:60px;height:60px;background-image:url(sprite/style.jpg);background-position:-180px 0}

同时生成sprite图片sprite/style.png和sprite/style.jpgLVS中国设计秀
LVS中国设计秀
LVS中国设计秀
文件对比:LVS中国设计秀

  before after
html before.htm after.htm
css style.source.css style.css
image png/gif总大小:10.2KBLVS中国设计秀
jpg总大小:8.69KBLVS中国设计秀
slice/1.pngLVS中国设计秀
LVS中国设计秀
slice/2.pngLVS中国设计秀
LVS中国设计秀
slice/3.pngLVS中国设计秀
LVS中国设计秀
slice/4.pngLVS中国设计秀
LVS中国设计秀
slice/6.gifLVS中国设计秀
LVS中国设计秀
slice/1.jpgLVS中国设计秀
LVS中国设计秀
slice/2.jpgLVS中国设计秀
LVS中国设计秀
slice/3.jpgLVS中国设计秀
LVS中国设计秀
slice/4.jpgLVS中国设计秀
5.83KBLVS中国设计秀
sprite/style.png LVS中国设计秀
7.19KBLVS中国设计秀
sprite/style.jpg

详解 碎图片放在slice文件夹,slice文件夹与css同级且引用时为相对路径 css调用图片的语句不能缩写,要写完整LVS中国设计秀

background-image:url('slice/1.png')

引号写单双无所谓,不写也行,最后都会被压缩掉,下面这种写法不会生效LVS中国设计秀

background:url('slice/1.png')

可处理png、gif(不支持动态gif,当作png8处理)和jpg格式,