<?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>等待喝彩_OnEcho &#187; CSS</title>
	<atom:link href="http://www.onecho.com/category/design/css/feed" rel="self" type="application/rss+xml" />
	<link>http://www.onecho.com</link>
	<description>http://www.onecho.com  回声的启示</description>
	<lastBuildDate>Fri, 16 Jul 2010 14:18:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>背景图片设置对CSS渲染效率的研究</title>
		<link>http://www.onecho.com/2008-09-17/374.html</link>
		<comments>http://www.onecho.com/2008-09-17/374.html#comments</comments>
		<pubDate>Wed, 17 Sep 2008 11:00:39 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[DIV]]></category>
		<category><![CDATA[渲染效率]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[背景图片设置对CSS渲染效率的研究]]></description>
			<content:encoded><![CDATA[<p>这篇文章主要讲了CSS对背景图片渲染效率的一些经验和研究：</p>
<p>书写高效的CSS &#8211; 漫谈CSS的渲染效率http://www.52css.com/article.asp?id=787</p>
<p>CSS对Web页面载入效率的影响http://www.52css.com/article.asp?id=751</p>
<p>树型结构竖线用样式表（背景图）来实现，样式表背景图片只需要加载一次，而现在这个模式（用多个&lt;img&gt;）图片虽然有缓存机制，但还是有可以每张小图片都请求一次服务器的，所以我想用样式表来实现有多么的好呀，代码又精简，结构又清晰，效果又酷，但是结果我将近一个星期的测试，我这种设想彻底失败，原因就是样式表的渲染效率太差。新的构想没能实现，心情有些沮丧，但我想也应该让大家分享一下这个测试成果。</p>
<p>这里我再解释一下树型里的竖线，树的左边都有 ┌ ├ └ │ 这些竖线图表示树层次，我的1.0版里是用一张张的小图片堆积起来的，而这种使用样式表的是用&lt;div class=&#8221;l2&#8243;&gt;&lt;/div&gt; （l是字母L）这种代码来实现的，样式表负责填充背景图。</p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><span style="color: #ff0000;">以下为引用的内容：</span><br />
Example Source Code [www.52css.com]<br />
#www_52css_com .l0{background:url(line0.gif) no-repeat center}<br />
#www_52css_com .l1{background:url(line1.gif) no-repeat center}<br />
#www_52css_com .l2{background:url(line2.gif) no-repeat center}<br />
#www_52css_com .l3{background:url(line3.gif) no-repeat center}<br />
#www_52css_com .l4{background:url(line4.gif) no-repeat center}<br />
#www_52css_com .ll{background:url(line5.gif) no-repeat center}<br />
#www_52css_com .pm0{background:url(plus0.gif) no-repeat center}<br />
#www_52css_com .pm1{background:url(plus1.gif) no-repeat center}<br />
#www_52css_com .pm2{background:url(plus2.gif) no-repeat center}<br />
#www_52css_com .pm3{background:url(plus3.gif) no-repeat center}<br />
#www_52css_com .expand .pm0{background:url(minus0.gif) no-repeat center}<br />
#www_52css_com .expand .pm1{background:url(minus1.gif) no-repeat center}<br />
#www_52css_com .expand .pm2{background:url(minus2.gif) no-repeat center}<br />
#www_52css_com .expand .pm3{background:url(minus3.gif) no-repeat center}</td>
</tr>
</tbody>
</table>
<p><span id="more-374"></span><br />
上面这段CSS是我在脚本里动态生成的一段样式的片段，我把它贴上来，有助于后面的讲解。运用样式表之后，果真精简了许多，每个节点的生成也够快，但我发现，当我的树节点量达到，比如说300-500个节点之后，节点生成的效率没有影响什么，但每个节点的展开/收缩很慢很慢，需要几秒钟以上甚至10秒，且这个期间的CPU占用率是100％。说明一下，树型的展开/收缩是设置父节点的 style.display = none|block 来实现的。我的电脑配置是：AMD2800+ 1GDDR400内存，配置不太差的。</p>
<p>我首先的反应是：是不是用了太多的&lt;table&gt;影响了效率？因为我每一个节点都用了一个&lt;table&gt;，但是我把&lt;table&gt;换成了&lt;div&gt;、&lt;span&gt;等，效率没有什么改善，说明这个CPU占用率100％的问题不是HTML标签的问题，那么剩下来的问题就是这里使用了样式表。</p>
<p>以一个500节点的量来说吧，1.0里左边大概要堆积2000个左右的小图片。这种情况在浏览器端设置本地不缓存的时候会存在很大的问题，要加载这些多的小图片需要消耗不少的时间和服务器资源，所以我才会有这种新的用样式表来解决的想法，现在换成样式表法，也就是大概有2000个地方需要用样式表来渲染出背景图。我测试了各种情况，再对比1.0版的代码得出的结论是：CPU的点用率如此之高，唯一的原因也就只有这种渲染的耗时了。验证也非常简单，我把上面的样式表的左边 #www_52css_com 这部分去掉，也就是去掉样式表的依托关系，测试的结果发现效率改善了很多，但耗时依然是可观的，有3-5秒之多。</p>
<p>另外我换了不同的浏览器，测试的结果也不太一样，在IE里最为恶心，比如说我在某个节点有500子节点，我将它收起（CPU100％，等待3-5秒），也就是display=&#8221;none&#8221;，这时候若我去收起这个节点的父节点（这个节点没有其它的同级节点，即它的父节点只有它这么一个子节点），照理说只有一个节点，收起应该是即时的事，但结果不然，结果又是3-5秒的CPU100％，这个让我狂郁闷，也就是说即使HTML对象被display=&#8221;none&#8221;隐藏掉了，但是对它的父级进行任何操作的时候，IE会对这些被隐藏的对象用样式表重新渲染一遍，真是搞不懂IE的开发者当初是怎么想的。</p>
<p>我又到FIREFOX里测试了一下，在收起的时候(display=none)是瞬间的，可以肯定，FF对待被隐藏的对象不会再消耗精力。当然展开的时候所有的浏览器都一样：3-5秒的CPU100％，不过FF稍微要快些。</p>
<p>通过上面的这些现象我得出这么一个结论：样式表在动态渲染的时候效率并不高；在父容器发现状态变化的时候会引起它的所以子孙对象的样式表重新渲染；FireFox 对待被display=none隐藏的对象不会重新渲染而IE会。</p>
<p>那么这种样式表的渲染效率问题以前为什么一直没有被发现呢？嘿嘿，大家做网页的时候难得会做到这种极端的时候，一个页面里有几千个需要样式表渲染背景图。通常也就几个地方或者几十个地方了，所以感觉不出来渲染的效率，也感觉不出这方面在不同的浏览器之间的差别。但是在做树这些的控件的时候必定会碰到各种极端的问题，比如大数据量的数组，生成的HTML对象的多少等等，象这种渲染的效率差别也只是我在写JS脚本时碰到的问题之一而已。今天我把这个测试结果共享出来是希望对大家以后写程序的时候有所借荐，在做设计的时候有所考虑。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onecho.com/2008-09-17/374.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>几个经典的css技巧</title>
		<link>http://www.onecho.com/2008-09-17/373.html</link>
		<comments>http://www.onecho.com/2008-09-17/373.html#comments</comments>
		<pubDate>Wed, 17 Sep 2008 11:00:25 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS技巧]]></category>
		<category><![CDATA[DIV]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[几个经典的css技巧]]></description>
			<content:encoded><![CDATA[<h3><strong>使用 line-height 垂直居中</strong></h3>
<p>line-height:24px;</p>
<p>使用固定宽度的容器并且需要一行垂直居中时，使用 line-height 即可（高度与父层容器一致），更多的垂直居中总结可以看这里。</p>
<h3><strong>清除容器浮动</strong></h3>
<p>#main {<br />
overflow:hidden;<br />
}</p>
<p><a href="http://www.gracecode.com/Archive/Display/1209" target="_blank">期前也提到过这样的问题</a>，更多信息可以看这里。</p>
<h3><strong>不让链接折行</strong></h3>
<p>a {<br />
white-space:nowrap;<br />
}</p>
<p>上面的设定就能避免链接折行，不过个人建议长链接会有相应的这行（有关换行方面的讨论，参看圆心的记录）。</p>
<h3><strong>始终让 Firefox 显示滚动条</strong></h3>
<p>html {<br />
overflow:-moz-scrollbars-vertical;<br />
}</p>
<p><span id="more-373"></span></p>
<p>更多的 Mozilla/Firefox 私有 CSS 属性可以参考这里。需跨浏览器的支持，也可以使用</p>
<p>body, html {<br />
min-height:101%;<br />
}</p>
<h3><strong>使块元素水平居中</strong></h3>
<p>margin:0 auto;</p>
<p>其实就是</p>
<p>margin-left: auto;<br />
margin-right: auto;</p>
<p>这个技巧基本上所有的 CSS 教科书都会有说明，别忘记给它加上个宽度。Exploer 下也可以使用</p>
<p>body{<br />
text-align: center;<br />
}</p>
<p>然后定义内层容器</p>
<p>text-align: left;</p>
<p>恢复。</p>
<h3><strong>隐藏 Exploer textarea 的滚动条</strong></h3>
<p>textarea {<br />
overflow:auto;<br />
}</p>
<p>Exploer 默认情况下 textarea 会有垂直滚动条（不要问我为什么）。</p>
<h3><strong>设置打印分页</strong></h3>
<p>h2 {<br />
page-break-before:always;<br />
}</p>
<p>page-break-before 属性能设置打印网页时的分页。</p>
<h3><strong>删除链接上的虚线框</strong></h3>
<p>a:active, a:focus {<br />
outline:none;<br />
}</p>
<p>Firefox 默认会在链接获得焦点（或者点击时）加上条虚线框，使用上面的属性可以删除。</p>
<h3><strong>最简单的 CSS 重置</strong></h3>
<p>* {<br />
margin: 0; padding: 0<br />
}</p>
<p>如果想“复杂”，参考<a href="http://developer.yahoo.com/yui/reset/" target="_blank">YUI 的做法</a>（还有这里）。原文留言中也有用户说了他们的观点</p>
<p>I have to agree with Niall Doherty, * {margin: 0px; padding: 0px;}<br />
basically means &#8220;traverse every css element and give it these<br />
attributes&#8221;. That is a very unnecessary strain on the server and<br />
a bad semantic practice, as you have to give some elements<br />
padding/margin again, after stripping them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onecho.com/2008-09-17/373.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>最常用的12种CSS BUG解决方法与技巧</title>
		<link>http://www.onecho.com/2008-08-17/375.html</link>
		<comments>http://www.onecho.com/2008-08-17/375.html#comments</comments>
		<pubDate>Sun, 17 Aug 2008 03:00:56 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[网络编程]]></category>
		<category><![CDATA[BUG]]></category>

		<guid isPermaLink="false">http://www.onecho.com/2008-08-17/375.html</guid>
		<description><![CDATA[CSS bug是布局中最头疼的问题。我们需要兼顾各种浏览器，以期待获得一致的效果。非常遗憾的是各厂商之间的竞争导致很多问题的存在。而IE6与IE7在很多问题上也存在着很大的差别。]]></description>
			<content:encoded><![CDATA[<p>CSS bug是布局中最头疼的问题。我们需要兼顾各种浏览器，以期待获得一致的效果。非常遗憾的是各厂商之间的竞争导致很多问题的存在。而IE6与IE7在很多问题上也存在着很大的差别。在52CSS.com大量的技术文档中，也包含了这方面的内容。轻松的解决CSS bug是我们必须掌握的技能。现在整理出最常用的12种CSS BUG解决方法以及CSS BUG类的小技巧。希望对您的学习、工作有所帮助，如果您依然有疑问，欢迎您到52CSS.com查阅、搜索相关内容。</p>
<p><strong>一、 针对浏览器的选择器</strong></p>
<p>这些选择器在你需要针对某款浏览器进行css设计时将非常有用。</p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">IE6及其更低版本<br />
* html {}<br />
IE7及其更低版本<br />
*:first-child+html {} * html {}<br />
仅针对IE7<br />
*:first-child+html {}<br />
IE7和当代浏览器<br />
html&gt;body{}<br />
仅当代浏览器(IE7不适用)<br />
html&gt;/**/body{}<br />
Opera9及其更低版本<br />
html:first-child {}<br />
Safari<br />
html[xmlns*=""] body:last-child {}</td>
</tr>
</tbody>
</table>
<p>要使用这些选择器,请将它们放在样式之前. 例如:</p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">#content-box {<br />
width: 300px;<br />
height: 150px;<br />
}</td>
</tr>
</tbody>
</table>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">* html #content-box {<br />
width: 250px;<br />
}</td>
</tr>
</tbody>
</table>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">当你想在一个浏览器里改变样式而不像在其他浏览器中改变时，这些选择器很有用。<br />
IE6以下</td>
</tr>
</tbody>
</table>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">*html{}</td>
</tr>
</tbody>
</table>
<p>IE 7 以下</p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">*:first-child+html {} * html {}</td>
</tr>
</tbody>
</table>
<p>只对IE 7</p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">*:first-child+html {}</td>
</tr>
</tbody>
</table>
<p>只对IE 7 和现代浏览器</p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">html&gt;body {}</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.onecho.com/2008-08-17/375.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
