<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>wlsy &#187; css sprites</title>
	<atom:link href="http://wlsy.me/tag/css-sprites/feed/" rel="self" type="application/rss+xml" />
	<link>http://wlsy.me</link>
	<description>当时的月亮 今天的阳光</description>
	<lastBuildDate>Tue, 24 Aug 2010 02:48:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>用css sprites(图片拼合)技术优化网站</title>
		<link>http://wlsy.me/107/</link>
		<comments>http://wlsy.me/107/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 20:09:12 +0000</pubDate>
		<dc:creator>wlsy</dc:creator>
				<category><![CDATA[Web前端]]></category>
		<category><![CDATA[css sprites]]></category>
		<category><![CDATA[优化]]></category>

		<guid isPermaLink="false">/2008/12/31/css-sprites.html</guid>
		<description><![CDATA[开篇先举个例子，假如你要从食堂送一些盒饭到每个寝室，你是用：得知订单中17#3单元3号寝室需要盒饭，然后你从食堂拿了一个盒饭送到该寝室，然后从订单中得知4号寝室也要盒饭，然后你有回到食堂拿了一盒给4号寝室。或者：你把订单中所需要的所有盒饭一起拿到寝室楼下，然后再发放。相信很多人都会选择后者，因为效率快。
css sprites技术就是为了减少客户端与服务器端的响应时间来加快网站载入速度。其实这项技术很早就有，但却相当的实用，所以还是整理一下，顺当温习。

一般说来客户端与服务器端进行一次http请求大概需要0.2s左右的时间，客户端每显示一张图片都会向服务器发送请求，所以，图片越多请求次数越多，造成延迟的可能性也就越大。如果你的网站有过多的图片，必然会拖慢速度。css sprites 的原理就是把所以的小图片拼合成一张图片，然后通过background-position来定位每张小图片。画了张图片能更形象的帮助理解：

举个按钮hover效果实例：

查看演示
CSS代码：

a{ width:100px;
 height:40px;
 background:url(/static/demo/g9net.gif) no-repeat;
 background-position:0 0;/*这个来定位*/
 display:block;
text-indent:-9999px;/*这样可以隐藏文字*/
}
a:hover{ background:url(/static/demo/g9net.gif) no-repeat;
 background-position:0 -40px;/*这个是hover状态的位置*/
 display:block;
}

html代码：

&#60;p&#62;&#60;a href="httP://www.g9net.com"&#62;G9neta&#62;p&#62;

这样原本需要进行两次请求变为了一次，当然了你可以将更多的小图片合成一种大图片。
有什么方法能快速的确定图片的background-position的值呢？
确实来确定background-position的值比较麻烦，不过可以通过这个链接能方便的进行拼合，关于它的介绍可以看这里
有那些网站使用了CSS sprites呢？
比如：Google picasa，可以看这张图片。
Yahoo.com首页，可以看这张图片。
当然了G9net也使用，还有很多，就不一一举例了。
css sprites存在的问题
维护不方便。
ie6会存在Background Flicker问题（影响不是很大。）解决的问题有很多方法可以参考：
Minimize Flickering CSS Background Images in IE6或者：
http://www.hedgerwow.com/360/bugs/dom-fix-ie6-background-image-flicker.html
PS：啥时IE6才能退出市场啊，对因为IE6而折寿的人肯定不少。
如果还有问题请留言。
ENDING
]]></description>
			<content:encoded><![CDATA[<p>开篇先举个例子，假如你要从食堂送一些盒饭到每个寝室，你是用：得知订单中17#3单元3号寝室需要盒饭，然后你从食堂拿了一个盒饭送到该寝室，然后从订单中得知4号寝室也要盒饭，然后你有回到食堂拿了一盒给4号寝室。或者：你把订单中所需要的所有盒饭一起拿到寝室楼下，然后再发放。相信很多人都会选择后者，因为效率快。</p>
<p>css sprites技术就是为了减少客户端与服务器端的响应时间来加快网站载入速度。其实这项技术很早就有，但却相当的实用，所以还是整理一下，顺当温习。</p>
<p><span id="more-107"></span></p>
<p>一般说来客户端与服务器端进行一次http请求大概需要0.2s左右的时间，客户端每显示一张图片都会向服务器发送请求，所以，图片越多请求次数越多，造成延迟的可能性也就越大。如果你的网站有过多的图片，必然会拖慢速度。css sprites 的原理就是把所以的小图片拼合成一张图片，然后通过background-position来定位每张小图片。画了张图片能更形象的帮助理解：</p>
<p><img src="http://lh3.ggpht.com/_cZCuU2AQABo/SVtVCByPjuI/AAAAAAAABks/tDCGetGJVbI/csssprites.gif?imgmax=800" alt="" /></p>
<p><strong>举个按钮hover效果实例：</strong></p>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:d4f538eb-6860-4ba4-a345-c0551d9f621a" class="wlWriterEditableSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<p><a href="/demo/css-sprites-buttom.html" target="_blank">查看演示</a></div>
<p>CSS代码：</p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">a{ <span style="color: #0000ff;">width</span>:<span style="color: #006080;">100px;</span>
 <span style="color: #0000ff;">height</span>:<span style="color: #006080;">40px;</span>
 <span style="color: #0000ff;">background</span>:url(/static/demo/g9net<span style="color: #cc6633;">.gif</span>) no<span style="color: #006080;">-repeat;</span>
 <span style="color: #0000ff;">background-position</span>:<span style="color: #006080;">0 0;</span><span style="color: #008000;">/*这个来定位*/</span>
 <span style="color: #0000ff;">display</span>:<span style="color: #006080;">block;</span>
<span style="color: #0000ff;">text-indent</span>:<span style="color: #006080;">-9999px;</span><span style="color: #008000;">/*这样可以隐藏文字*/</span>
}
a:hover{ <span style="color: #0000ff;">background</span>:url(/static/demo/g9net<span style="color: #cc6633;">.gif</span>) no<span style="color: #006080;">-repeat;</span>
 <span style="color: #0000ff;">background-position</span>:0 <span style="color: #006080;">-40px;</span><span style="color: #008000;">/*这个是hover状态的位置*/</span>
 <span style="color: #0000ff;">display</span>:<span style="color: #006080;">block;</span>
}</pre>
</div>
<p>html代码：</p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">p</span><span style="color: #0000ff;">&gt;&lt;</span><span style="color: #800000;">a</span> <span style="color: #ff0000;">href</span><span style="color: #0000ff;">="httP://www.g9net.com"</span><span style="color: #0000ff;">&gt;</span>G9net<span style="color: #0000ff;"><!--</span--><span style="color: #800000;">a</span><span style="color: #0000ff;">&gt;<!--</span--><span style="color: #800000;">p</span><span style="color: #0000ff;">&gt;</span></span></span></pre>
</div>
<p>这样原本需要进行两次请求变为了一次，当然了你可以将更多的小图片合成一种大图片。</p>
<p><strong>有什么方法能快速的确定图片的background-position的值呢？</strong></p>
<p>确实来确定background-position的值比较麻烦，不过可以通过<a href="http://spritegen.website-performance.org/" target="_blank">这个链接</a>能方便的进行拼合，关于它的介绍可以看<a href="http://www.g9net.com/2008/12/30/css-sprites-online.html" target="_blank">这里</a></p>
<p><strong>有那些网站使用了CSS sprites呢？</strong></p>
<p>比如：Google picasa，可以看<a href="http://lh4.ggpht.com/s/v/43.10/styles/../img/lh_sprite.gif" target="_blank">这张图片</a>。</p>
<p>Yahoo.com首页，可以看<a href="http://l.yimg.com/a/i/ww/sp/trough_2.0_062308.gif" target="_blank">这张图片</a>。</p>
<p>当然了<a href="http://www,g9net.com" target="_blank">G9net</a>也使用，还有很多，就不一一举例了。</p>
<p><strong>css sprites存在的问题</strong></p>
<p>维护不方便。</p>
<p>ie6会存在Background Flicker问题（影响不是很大。）解决的问题有很多方法可以参考：</p>
<p><a href="http://www.fivesevensix.com/studies/ie6flicker">Minimize Flickering CSS Background Images in IE6</a>或者：</p>
<p><a href="http://www.hedgerwow.com/360/bugs/dom-fix-ie6-background-image-flicker.html">http://www.hedgerwow.com/360/bugs/dom-fix-ie6-background-image-flicker.html</a></p>
<p>PS：啥时IE6才能退出市场啊，对因为IE6而折寿的人肯定不少。</p>
<p>如果还有问题请留言。</p>
<p>ENDING</p>
]]></content:encoded>
			<wfw:commentRss>http://wlsy.me/107/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>css sprites 图片在线拼合网站</title>
		<link>http://wlsy.me/65/</link>
		<comments>http://wlsy.me/65/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 05:42:10 +0000</pubDate>
		<dc:creator>wlsy</dc:creator>
				<category><![CDATA[琐事杂念]]></category>
		<category><![CDATA[css sprites]]></category>

		<guid isPermaLink="false">/2008/12/30/css-sprites-online.html</guid>
		<description><![CDATA[CSS 图片拼合 (CSS sprites) 可以有效降低图片文件的 HTTP 连接请求数. 简单的将能够将多个小图片拼合成一张图片，然后通过background-position来定位。关于css sprites技术将更有详细的介绍。css sprites最麻烦的就是background-postion的值，而css图片拼合生成器这个网站能很方便的帮你生产background-postion的值。
&#160;

]]></description>
			<content:encoded><![CDATA[<p>CSS 图片拼合 (CSS sprites) 可以有效降低图片文件的 HTTP 连接请求数. 简单的将能够将多个小图片拼合成一张图片，然后通过background-position来定位。关于css sprites技术将更有详细的介绍。css sprites最麻烦的就是background-postion的值，而<a href="http://spritegen.website-performance.org/">css图片拼合生成器</a>这个网站能很方便的帮你生产background-postion的值。<span id="more-65"></span></p>
<p>&#160;</p>
<p><img style="display: inline; margin-left: 0px; margin-right: 0px" src="http://lh3.ggpht.com/_cZCuU2AQABo/SVok5Q1fYZI/AAAAAAAABUk/9AzD8q-YsW4/a.png?imgmax=800" /></p>
]]></content:encoded>
			<wfw:commentRss>http://wlsy.me/65/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
