市面上有一些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
文件對比:
background-image:url('slice/1.png')
引號寫單雙無所謂,不寫也行,最後都會被壓縮掉,下面這種寫法不會生效
background:url('slice/1.png')
View more videos from ytzong