首页 > 开发 > CSS > 正文

CssGaga教程:AutoSprite(CSS Sprite Generator)

2024-07-11 09:02:35
字体:
来源:转载
供稿:网友

武林网(www.vevb.com)文章简介:CssGaga – AutoSprite(CSS Sprite Generator).

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

<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源文件:

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生成后:

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.jpg

文件对比:

 beforeafter

htmlbefore.htmafter.htm

cssstyle.source.cssstyle.css

imagepng/gif总大小:10.2KB
jpg总大小:8.69KB
slice/1.png
5.83KB
sprite/style.png

详解
  • 碎图片放在slice文件夹,slice文件夹与css同级且引用时为相对路径
  • css调用图片的语句不能缩写,要写完整background-image:url('slice/1.png')

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

    background:url('slice/1.png')
  • CssGaga – AutoSprite

     

    View more videos from ytzong

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表