<?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>随网之舞CSS</title>
	<atom:link href="http://dancewithnet.com/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://dancewithnet.com</link>
	<description>WEB Design{HTML:CSS:Javascript:DOM:AJAX:PHP:Usability}/Viewpoint/Photo/Food/Mood</description>
	<lastBuildDate>Mon, 18 Jul 2011 02:45:29 +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>默认Web字体样式</title>
		<link>http://dancewithnet.com/2009/11/22/default-web-font-style/</link>
		<comments>http://dancewithnet.com/2009/11/22/default-web-font-style/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 10:36:22 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[arial]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[font-family]]></category>
		<category><![CDATA[宋体]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1491</guid>
		<description><![CDATA[通常用户看到的页面的样式会受到三层控制，第一层是浏览器的默认样式，第二层是网页定义样式，第三层是用户自定义样式。和CSS一样，后面的优先级高于前面的，也就是说网页定义样式可... ]]></description>
			<content:encoded><![CDATA[<p>通常用户看到的页面的样式会受到三层控制，第一层是浏览器的默认样式，第二层是网页定义样式，第三层是用户自定义样式。和CSS一样，后面的优先级高于前面的，也就是说网页定义样式可以覆盖浏览器的默认样式，而用户自定义样式优先级最高。实际情况是虽然浏览器都或多或少提供了用户自定义样式的功能，但是极少数会有用户去自定义，一般用也是高级用户。而浏览器默认的样式往往在不同的浏览器、不同的语言版本甚至不同的系统版本都有不同的设置，这就导致如果直接利用默认样式的页面在各个浏览器下显示非常不一致，于是就有了类似<a href="http://developer.yahoo.com/yui/3/cssreset/">YUI的reset</a>之类用来尽量重写浏览器的默认设置保证各个浏览器样式一致性的做法。</p>
<p>拿字体来说，各个浏览器默认的字体种类、字体大小和字体行高都不一样，比如IE8的中文版在Windows XP下显示网页时默认字体是宋体，而英文版肯定不会如此。所以我们需要统一设置默认的字体样式，以便实现一致的显示效果来保证设计的一致性和提高开发效率。</p>
<p>以后准备使用如下默认字体样式：</p>
<pre><code>body{
  font: 12px/1.5 arial;
}</code></pre>
<p><span id="more-1491"></span></p>
<h3>字体：<a href="http://www.designworkplan.com/typography-fonts/arial-is-everywhere.htm">arial</a></h3>
<p>我们页面的绝大部分内容字符都是中文，毫无疑问目前为止在网页上最常用也是最通用的显示中文的字体是宋体，但是<a href="http://dancewithnet.com/lab/2009/web-font/">宋体在显示英文、数字和英文符号时过于糟糕</a>，比如&copy;字符，所以我们一般期望通过CSS来实现用更好的字体样式来显示它们，然后用宋体来显示中文和中文符号。之所以选择arial是因为：</p>
<ol>
<li>Windows和Mac都预装了这款字体，应该是使用最广泛的网页字体了。它的潜在对手<code>tahoma</code>和<code>helvetica</code>就没有这么幸运了。</li>
<li>视觉设计的专业人士可能会认为<a href="http://www.cnblogs.com/ruxpinsp1/archive/2008/05/11/font-in-front-end-development-4.html">在Windows中使用tahoma、在Mac中使用helvetica</a>更好，比如<a href="http://lifesinger.org/blog/2009/08/font-family-in-css/">淘宝的默认字体样式</a>是<code>font: 12px/1 Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;<br />
</code>这是一个很不错的选择，但是你也会发现Google、YAHOO、Youtube、Bing甚至<a href="http://www.msn.com/preview.aspx">MSN的新版</a>都使用<code>arial</code>作为第一默认字体。所以从美观和可读性上来讲<code>arial</code>应该是完全可以接受的。</li>
<li>一般情况下设置font-family都会在最后设置<a href="http://www.cnblogs.com/ruxpinsp1/archive/2008/04/29/font-in-front-end-development-1.html">通用字体族</a>以保证其安全性，比如Google的设置为<code>font-family:arial,sans-serif;</code>，但是至少在非中文版的Win7下当编码是GBK时，IE8会因<code>sans-serif</code>来渲染宋体，导致字体出现变形，这就是为什么淘宝需要在<code>sans-serif</code>前加上宋体而Google无需这样做的原因。</li>
<li>因为中文字体的选择非常有限，所以目前所有的主流浏览器都设置使用宋体来显示中文。Baidu的首页和搜索结果页使用<code>font-family:arial;</code>可以从侧面说明这样做的安全性。可能有人注意到<a href="http://g-fox.cn/">Firefox中国版</a>默认显示的中文字体是微软雅黑，这是因为谋智网络擅自修改了用户自定义样式，不允许网页的样式覆盖浏览器设置的样式。也是由于类似的情况，我们要弹性设计网页非常重要。</li>
</ol>
<p>使用英文字体作为第一默认字体会导致的问题之一就是<a href="http://dancewithnet.com/lab/2009/web-font/">中英文以及符号混排时的对齐问题</a>、通过设置行高和hasLayout能解决绝大部分情况，但是都不会很完美，如果把字体改成“宋体”能彻底的解决问题。很明显，这个问题只出现在IE上。所以，如果你的网站很少使用英文、数字和英文符号，那么直接设置<code>{font-family:\5b8b\4f53;}</code>也是很合理的选择。</p>
<h3>大小：12px</h3>
<ol>
<li>12px是宋体能显示的极限，<a href="http://www.docin.com/p-2647154.html">虽然微软雅黑能显示更小的字体</a>，但目前的应用环境尚未成熟。由于宋体基本上是目前显示中文唯一的通用Web字体，所以12px成为最常用的字体大小。我们当然可以依据产品的需要来修改这个默认值。</li>
<li><a href="http://dancewithnet.com/2008/06/17/it-is-time-to-discard-font-size-adjustments/">不用考虑基于字体大小（em）的设计</a>。</li>
<li>在Chrome3.0之后的中文版中，字体大小最小值是12px，比如你设置最小字体为10px，最后也变成12px。</li>
</ol>
<h3>行高：1.5倍</h3>
<ol>
<li>这是一个经验值，不同的产品对这个值要求可能不同，但我们一般会设置最常用的为默认值。比如<a href="http://developer.yahoo.com/yui/3/cssfonts/">YUI的font</a>中是<code>font:13px/1.231 arial,helvetica,clean,sans-serif;</code>即字体大小默认值是13px，行高是13*1.231=16.003px，默认的行高是默认字体的1.231倍。对于中文来说，常用的字体大小12px、14px、16px、18px等偶数大小，在IE6和IE7设置其行高也为偶数能解决一些特殊情况下的字体对其问题。</li>
<li>在IE6和IE7中，行高值必须大于字体的2px才能保证字体的完整显示或当其作为链接时能有效显示下划线。</li>
<li>设置<code>line-height</code>时，<a href="http://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/">注意不要使用单位（包括%在内）</a>，因为子节点会继承经过运算后的line-height值，所以当使用单位后浏览器会把<code>line-height</code>计算成第一次定义的绝对值，而不会随着字体大小的变化而变化，而无单位的数值表示是所在容器的<code>font-size</code>的倍数，所以设置为无单位的数值是最佳选择。</li>
<li><a href="http://webteam.tencent.com/?p=1503">深入CSS 行高</a>非常有利于理解<code>line-height</code>，值得一读。</li>
</ol>
<h3>性能和效率</h3>
<ol>
<li>大部分平台都有<code>arial</code>，减少浏览器的查找时间。</li>
<li>代码最少，书写方便。<code>arial</code>基本上是名字最短的字体了，可以节约CSS的大小。</li>
<li>所有的字母都小写，目前Google就是这样做的，好处是既可以编写更快也能<a href="http://code.google.com/speed/page-speed/docs/payload.html#GzipCompression">提升Gzip压缩的效率</a>。</li>
<li><a href="http://lifesinger.org/blog/2009/08/font-family-in-css/">中文最好用unicode表示</a>，比如使用宋体是<code>{font-family:\5b8b\4f53;}</code>，使用微软雅黑是<code>{font-family:\5fae\8f6f\96c5\9ed1;}</code>，这样的好处是避免编码问题，同时能得到所有的主流浏览器的支持。</li>
<li><a href="http://www.cnblogs.com/ruxpinsp1/archive/2008/05/11/font-in-front-end-development-4.html">使用正确的字体种类写法，避免使用引号</a>，这样可以缩小CSS的大小。中文字体可以按上一条方式来编写。</li>
</ol>
<h3>未来</h3>
<ol>
<li>通过对<a href="http://dancewithnet.com/lab/2009/web-font/">中英文及符号混排的测试</a>，我发现微软雅黑其实表现相当不错，包括英文数字和英文字符以及在IE6和IE7的显示效果上，但唯一的遗憾是在XP下如果安装了微软雅黑字体的用户没有打开“使用屏幕字体的边缘平滑”选项的话，在Firefox、Safari和Opera、特别是IE6下会非常模糊难以辨认。针对这个问题目前并没有很好的解决方案，所以只有等到IE6使用比率非常小的时候才可能正式的使用它。或许需要到2014年，XP死掉的时候。</li>
<li>虽然很早就有了@font-face，但是浏览器的支持、网速和商业问题，导致它很少被应用。最近关于字体的好消息是<a href="http://internet.solidot.org/internet/09/11/03/0646210.shtml">Firefox3.6将支持Web Open Font Forma</a>。关于Web字体未来的相关信息可以看<a href="http://www.comsharp.com/GetKnowledge/zh-CN/CMS_K441.aspx">Web 字体的未来</a>、<a href="http://www.comsharp.com/GetKnowledge/zh-CN/It_News_K830.aspx">关于 Web 字体：现状与未来</a>和<a href="http://www.comsharp.com/GetKnowledge/zh-CN/It_News_K832.aspx">再谈 Web 字体的现状与未来</a>。</li>
</ol>
<p>最后推荐一下玉伯的<a href="http://lifesinger.org/blog/2009/11/web-default-font/">《再谈 Web 默认字体》</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2009/11/22/default-web-font-style/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>IE中选择符的4095限制</title>
		<link>http://dancewithnet.com/2009/09/10/ie-css-4095-limit/</link>
		<comments>http://dancewithnet.com/2009/09/10/ie-css-4095-limit/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 15:42:42 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[4095]]></category>
		<category><![CDATA[addRule]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[cssText]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1471</guid>
		<description><![CDATA[去年曾总结了《IE对CSS样式表的限制和解决方案》中限制的第4条写道“一个CSS文件的不能超过288kb？”，这是一个疑问句，当时没有重现出来且参考来自Internet Explorer CSS File Size Limit。今天终于... ]]></description>
			<content:encoded><![CDATA[<p>去年曾总结了<a href="http://dancewithnet.com/2008/04/22/a-solution-of-limit-of-style-tags-in-ie/">《IE对CSS样式表的限制和解决方案》</a>中限制的第4条写道“一个CSS文件的不能超过288kb？”，这是一个疑问句，当时没有重现出来且参考来自<a href="http://joshua.perina.com/africa/gambia/fajara/post/2008/1/25/internet-explorer-css-file-size-limit">Internet Explorer CSS File Size Limit</a>。今天终于看到了IE在CSS上的另一个限制：<strong>IE中每个style标签或css文件的选择符个数不能超过4095。</strong>其实style属性也应该有这个限制，但是几乎不可能发生。这个限制在IE6、IE7和IE8中存在。请看<a href="http://dancewithnet.com/lab/2009/ie-css-4095-limit/" class="link-btn">IE关于4095个选择符限制的DEMO</a>。</p>
<p><span id="more-1471"></span></p>
<p>DEMO中的<a href="http://dancewithnet.com/lab/2009/ie-css-4095-limit/style.css">style.css</a>有4913个选择符，大小为554kb，但在IE中却在4095个选择符之后失效，所以说明IE的CSS文件不存在不能超过288kb的限制。</p>
<p>所以在IE中对style标签使用<a href="http://msdn.microsoft.com/en-us/library/aa358796%28VS.85%29.aspx">addRule方法</a>和<a href="http://msdn.microsoft.com/en-us/library/ms533698(VS.85).aspx">cssText属性</a>添加样式时都可能会碰到这个限制，比如使用addRule方法添加第4096个选择符时会报“Invalid Argument”的异常。</p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2009/09/10/ie-css-4095-limit/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>CSS实现HTML元素透明的那些事</title>
		<link>http://dancewithnet.com/2009/09/06/css-opacity/</link>
		<comments>http://dancewithnet.com/2009/09/06/css-opacity/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 15:44:00 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[Javascript & DOM & AJAX]]></category>
		<category><![CDATA[-ms-filter]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[hasLayout]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[opacity]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1469</guid>
		<description><![CDATA[CSS3草案中定义了{opacity:&#60;length&#62; &#124; inherit;}来声明元素的透明度，这已经得到了大多数现代浏览器的支持，而IE则很早通过特定的私有属性filter来实现的，所以HTML元素的透明效果已经无处... ]]></description>
			<content:encoded><![CDATA[<p>CSS3草案中定义了<a href="http://www.w3.org/TR/css3-color/#transparency"><code>{opacity:&lt;length&gt; | inherit;}</code></a>来声明元素的透明度，这已经得到了大多数现代浏览器的支持，而IE则很早通过特定的私有属性<a href="http://msdn.microsoft.com/en-us/library/ms532967%28VS.85%29.aspx"><code>filter</code></a>来实现的，所以HTML元素的透明效果已经无处不在了。首先看看<a href="http://developer.yahoo.com/yui/articles/gbs/">A级浏览器</a>所支持的用<a href="https://developer.mozilla.org/en/CSS/opacity">CSS实现元素透明的方案</a>：</p>
<p><span id="more-1469"></span></p>
<table>
<tr>
<th>浏览器</th>
<th>最低<br />版本</th>
<th>方案</th>
</tr>
<tr>
<th rowspan="3">Internet Explorer</th>
<td>4.0</td>
<td><code>filter: alpha(opacity=xx);</code></td>
</tr>
<tr>
<td>5.5</td>
<td><code>filter: progid:DXImageTransform.Microsoft.Alpha(opacity=xx);</code>
</td>
</tr>
<tr>
<td>8.0</td>
<td><code>filter: "alpha(opacity=xx)";<br />
filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=xx)";<br />
-ms-filter: "alpha(opacity=xx)";<br />
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=30)";</code>
</td>
</tr>
<tr>
<th>Firefox (Gecko)</th>
<td>0.9 (1.7)</td>
<td><code>opacity</code></td>
</tr>
<tr>
<th>Opera</th>
<td>9.0</td>
<td><code>opacity</code></td>
</tr>
<tr>
<th>Safari (WebKit)</th>
<td>1.2 (125)</td>
<td><code>opacity</code></td>
</tr>
</table>
<p>实际上在IE8中，-ms-filter是filter的别名，两者区别是<a href="http://msdn.microsoft.com/en-us/library/ms530752%28VS.85%29.aspx">-ms-filter的属相值必须被单引号或双引号包围</a>，而filter中则不是必须，而在IE8之前的版本中，filter的属性值必须不被单引号或双引号包围。</p>
<p id="hasLayout">IE中的HTML元素要实现透明，则其必须具备layout，这样的元素有仅可读的属性<a href="http://msdn.microsoft.com/en-us/library/ms530764%28VS.85%29.aspx">hasLayout</a>，且其值为true。具体情况如下：</p>
<ol>
<li><code>body</code>、<code>img</code>、<code>table</code>、<code>tr</code>、<code>th</code>、<code>td</code>等元素的<code>hasLayout</code>一直为<code>true</code>。</li>
<li><code>type</code>为<code>text</code>、<code>button</code>、<code>file</code>或<code>select</code>的<code>input</code>的<code>hasLayout</code>一直为<code>true</code>。</li>
<li>设置<code>{position:absolute}</code>的元素的<code>hasLayout</code>为<code>true</code></li>
<li>设置<code>{float:left|right}</code>的元素的<code>hasLayout</code>为<code>true</code></li>
<li>设置<code>{display:inline-block}</code>的元素的<code>hasLayout</code>为<code>true</code></li>
<li>设置<code>{height:xx}</code>或<code>{width:xx}</code>的元素必须具体以下两个条件之一，其<code>hasLayout</code>才能为<code>true</code>：
<ol>
<li>IE8兼容模式和IE8以前的浏览器中，在标准(strict)模式下其<code>display</code>的值是<code>block</code>，如<a href="http://dancewithnet.com/lab/2009/css-opacity/#demo3">demo3</a>就不行。</li>
<li>元素在怪癖模式（compat mode）下。</li>
</ol>
</li>
<li>设置了<code>{zoom:xx}</code>的元素在IE8的兼容模式或IE8之前的浏览器中其<code>hasLayout</code>为<code>true</code>，但在IE8的标准模式下则不会触发<code>hasLayout</code>。</li>
<li>设置了<code>{writing-mode:tb-rl}</code>的元素的<code>hasLayout</code>为<code>true</code>。</li>
<li>元素的<a href="http://msdn.microsoft.com/en-us/library/ms537837%28VS.85%29.aspx"><code>contentEditable</code></a>的属性值为<code>true</code>。</li>
<li>在IE8标准模式下设置了<code>{display:block}</code>的元素的<code>hasLayout</code>一直为<code>true</code>，如<a href="http://dancewithnet.com/lab/2009/css-opacity/#demo8">demo8</a>。</li>
</ol>
<p>关于hasLayout的更多详情可以看<a href="http://msdn.microsoft.com/en-us/library/bb250481%28VS.85%29.aspx">Exploring Internet Explorer &#8220;HasLayout&#8221; Overview</a>和<a href="http://www.satzansatz.de/cssd/onhavinglayout.html">On having layout</a></p>
<p>从上面就可以看出IE实现HTML元素的透明如此混乱，为了向下兼容和自己的私有属性让IE上实现元素透明有多种方式，比如<a href="http://dancewithnet.com/lab/2009/css-opacity/" class="link-btn">CSS Opacity实例中的demo1到demo8</a>，虽然<a href="http://blogs.msdn.com/ie/archive/2008/09/08/microsoft-css-vendor-extensions.aspx">IE团队推荐实现透明的方式</a>是：</p>
<pre><code>{
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
  opacity: .5;
}</code></pre>
<p>而目前简单最好用的实现方式是<a href="http://dancewithnet.com/lab/2009/css-opacity/" class="link-btn">如CSS Opacity中demo4这样</a>：</p>
<pre><code>{
    filter:alpha(opacity=30);
    opacity:.3;
}</code></pre>
<p>实际上目前最流行的JavaScript框架的设置样式方法都是应用这种方式，并且针对IE设置了<code>{zoom:1}</code>来让元素的<code>hasLayout</code>为<code>true</code>，但在IE8的标准模式下<code>zoom</code>并不能触发<code>hasLayout</code>，所以利用它们设置<code>hasLayout</code>为<code>false</code>的元素的透明度时在IE8的标准模式下是失败的，这个bug在<a href="http://developer.yahoo.com/yui/">YUI</a><ins datetime="2009-09-09T09:38:41+08:00">（我已经给YUI团队提交了这个bug，他们会在<a href="http://yuilibrary.com/projects/yui2/ticket/2528440">下个版本修复</a>，最新的2.8.0中依旧存在，期待2.9.0吧）</ins>、<a href="http://prototypejs.org">Prototype</a>、<a href="http://jquery.com">jQuery</a>和<a href="http://mootools.net">Mootools</a>的最新版本中都存在，具体请在IE8标准模式下看<a href="http://dancewithnet.com/lab/2009/css-opacity/#demo9">demo9到demo11</a>。同样由于在IE8中设置透明度的方式多种多样，所以利用JavaScript获取HTML元素的透明度值需要考虑多种情况，YUI完美解决了这个问题，Prototype比jQuery稍微周全一点，而Mootools直接是<a href="https://mootools.lighthouseapp.com/projects/2706/tickets/707-getstyleopacity-always-returns-1">bug</a>，具体可以<a href="http://dancewithnet.com/lab/2009/css-opacity/" class="link-btn">在IE下看demo1到demo8</a>的演示。从这个角度给4个框架来个排名的话，YUI第一、Prototype第二、jQuery第三、Mootools垫底。</p>
<p>我简单的实现了设置和获取Opacity的函数，可以避开上面框架存在的bug，请<a href="http://dancewithnet.com/lab/2009/css-opacity/#demo12" class="link-btn">在IE8标准模式下看demo12</a>：</p>
<pre><code><span>//设置CSS opacity 属性的函数，解决IE8的问题</span>
var setOpacity = function(el,i){
  if(window.getComputedStyle){<span>// for non-IE</span>
    el.style.opacity = i;
  }else if(document.documentElement.currentStyle){ <span>// for IE</span>
    if(!el.currentStyle.hasLayout){
      el.style.zoom = 1;
    }
    if(!el.currentStyle.hasLayout){ <span>//在IE8中zoom不生效，所以再次设置inline-block</span>
      el.style.display = 'inline-block';
    }
    try{
      <span>//测试是否已有filter
      //http://msdn.microsoft.com/en-us/library/ms532847%28VS.85%29.aspx</span>
      if(el.filters){
        if(el.filters('alpha')){
	  el.filters('alpha').opacity = i * 100;
	}else{
	  el.style.filter += 'alpha(opacity='+ i * 100 +')';
	 }
       }
    }catch(e){
      el.style.filter = 'alpha(opacity='+ i * 100 +')';
    }
  }
}

<span>//获取CSS opacity 属性值的函数</span>
<span>//借鉴自http://developer.yahoel.com/yui/docs/YAHOO.util.Dom.html#method_getStyle</span>
var getOpacity = function(el){
  var value;
  if(window.getComputedStyle){
    value = el.style.opacity;
    if(!value){
      value = el.ownerDocument.defaultView.getComputedStyle(el,null)['opacity'];
    }
    return value;
  }else if(document.documentElement.currentStyle){
    value = 100;
    try { // will error if no DXImageTransform
        value = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
    } catch(e) {
        try { // make sure its in the document
            value = el.filters('alpha').opacity;
        } catch(err) {
        }
    }
    return value / 100;
  }
}
</code></pre>
<p>不得不说，这些事都是IE整出来的……</p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2009/09/06/css-opacity/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>border-radius与圆角</title>
		<link>http://dancewithnet.com/2008/12/27/border-radius-and-rounded-corner/</link>
		<comments>http://dancewithnet.com/2008/12/27/border-radius-and-rounded-corner/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 11:25:55 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[border-radius]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[跨浏览器]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1412</guid>
		<description><![CDATA[两年前发表的《The visual design of Web 2.0》中提到“Rounded everything”，圆角因使人感觉舒适的友好风格而变得无处不在。这个无处不在也让很多前端工程师累个半死，YAHOO Performance Research Engneer Team... ]]></description>
			<content:encoded><![CDATA[<p>两年前发表的<a href="http://f6design.com/journal/2006/10/21/the-visual-design-of-web-20/">《The visual design of Web 2.0》</a>中提到“Rounded everything”，圆角因使人感觉舒适的友好风格而变得无处不在。这个无处不在也让很多前端工程师累个半死，<a href="http://developer.yahoo.com/performance/">YAHOO Performance Research Engneer Team</a>的Nicole在讲演<a href="http://www.slideshare.net/stubbornella/designing-fast-websites-presentation">《Designing Fast Websites》</a>中用的副标题是don&#8217;t blame the rounded corners!，从侧面也说明了圆角给实现者带来的困扰：实现麻烦、兼容困难、性能不佳。而W3C早在<a href="http://www.w3.org/TR/2002/WD-css3-border-20021107/#the-border-radius">2002年的CSS3草案中</a>就加入了一个叫<a href="http://www.w3.org/TR/css3-background/#the-border-radius">border-radius</a>的属性，通过它可以直接来定义HTML元素的圆角。<span id="more-1412"></span></p>
<h3>CSS3的border-radius规范</h3>
<p><a href="http://www.w3.org/TR/css3-background/#the-border-radius">最新草案</a>中其主要信息如下：</p>
<ol>
<li>属性：<code>border-top-right-radius</code><br />
　　　<code>border-bottom-right-radius</code><br />
　　　<code>border-bottom-right-radius</code><br />
　　　<code>border-bottom-right-radius</code><br />
值：&lt;length&gt; &lt;length&gt;?。它们分别是定义角形状的四分之一椭圆的两个半径。如图：<br />
<img src="http://www.w3.org/TR/2005/WD-css3-background-20050216/corner.png" width="289" height="179" alt="border-radius" /></p>
<ol>
<li>第一个值是水平半径。</li>
<li>如果第二个值省略，则它等于第一个值，这时这个角就是一个四分之一圆角。</li>
<li>如果任意一个值为0，则这个角是矩形，不会是圆的。</li>
<li>值不允许是负值。</li>
</ol>
</li>
<li>属性：border-radius。它是上面四个属性值的简写。<br />
值：&lt;length&gt;{1,4} [ / &lt;length&gt;{1,4} ]?</p>
<ol>
<li>如果斜线前后的值都存在，那么斜线前的值设置水平半径，且斜线后的值设置垂直半径。如果没有斜线，则水平半径和垂直半径相等。</li>
<li>四个值是按照top-left、top-right、 bottom-right、 bottom-left的顺序来设置的。如果bottom-left省略，那么它等于top-right。如果bottom-right省略，那么它等于top-left。如果top-right省略，那么它等于top-left。</li>
</ol>
</li>
<li>应用范围：所有的元素，除了table的样式属性<code>border-collapse</code>是<code>collapse</code>时</li>
<li>内边半径等于外边半径减去对应边的厚度。当这个结果是负值时，内边半径是0。所以内外边曲线的圆心并不一定是一致的。</li>
<li>border-radius也会导致该元素的背景也是圆的，即使<code>border</code>是<code>none</code>。如果<a href="http://www.w3.org/TR/css3-background/#background-clip">background-clip</a>是padding-box，则背景（background）会被曲线的内边裁剪。如果是border-box则被外边裁剪。border和padding定义的区域也一样会被曲线裁剪。</li>
<li>所有的边框样式（<code>solid</code>、<code>dotted</code>、<code>inset</code>等）都遵照角的曲线。如果设置了border-image，则曲线以外的部分会被裁剪掉。</li>
<li>如果角的两个相邻边有不同的宽度，那么这个角将会从宽的边平滑过度到窄的边。其中一条边甚至可以是0。</li>
<li>两条相邻边颜色和样式转变的中心点是在一个和两边宽度成正比的角上。比如，两条边宽度相同，这个点就是一个45°的角上，如果一条边是另外一条边的两倍，那么这个点就在一个30°的角上。界定这个转变的线就是连接在内外曲线上的两个点的直线</li>
<li>角不允许相互重叠，所以当相邻两个角半径的和大于所在矩形区域的大小时，用户代理（浏览器）比如缩小一个或多个角半径。运算法则如下：f = min(L<sub>i</sub>/S<sub>i</sub>)，i ∈ {top, right, bottom, left}，L<sub>top</sub> = L<sub>bottom</sub> = 所在矩形区域的宽，L<sub>left</sub> = L<sub>right</sub> = 所在矩形区域的高。如果f < 1，那么所有角半径都乘以f。</li>
</li>
</ol>
<h3>浏览器支持</h3>
<p>实际中，目前没有任何一款浏览器支持这个属性，只有部分浏览器利用其私有属性支持部分实现：</p>
<ol>
<li><a href="https://developer.mozilla.org/en/CSS/-moz-border-radius">Firefox对border-radius的支持</a>：
<pre><code>-moz-border-radius: &lt;length&gt;{1,4} | inherit
-moz-border-radius-bottomleft : &lt;length&gt; | inherit
-moz-border-radius-bottomright  : &lt;length&gt; | inherit
-moz-border-radius-topleft  : &lt;length&gt; | inherit
-moz-border-radius-topright : &lt;length&gt; | inherit
</code></pre>
<ol>
<li>只对每个角设置一个半径，只支持实现四分之一圆角，并不支持椭圆形圆角。</li>
<li>具体每个角的命名规则也和W3C不一致，这个比较讨厌。</li>
<li>Firefox3圆角已经相当圆滑了，Firefox2比较糟糕，好在它即将终结了。</li>
</ol>
</li>
<li><a href="http://developer.apple.com/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/css/property/-webkit-border-radius">Safari和Chrome对border-radius的支持</a>：
<pre><code>-webkit-border-radius: &lt;length&gt;{1,2} | inherit
-webkit-border-bottom-left-radius : &lt;length&gt;{1,2} | inherit
-webkit-border-bottom-right-radius : &lt;length&gt;{1,2} | inherit
-webkit-border-top-left-radius  : &lt;length&gt;{1,2} | inherit
-webkit-border-top-right-radius : &lt;length&gt;{1,2} | inherit
</code></pre>
<ol>
<li>每个属性有1个或2个值，当有两个值时1个表示水平半径，一个表示垂直半径（当writing-mode改变也随之而变）。所以，Safari和Chrome中的圆角可以是椭圆角。</li>
<li>webkit的实现方法和<a href="http://www.w3.org/TR/2005/WD-css3-background-20050216/#the-border-radius">W3C的CSS3草案2005年版本</a>非常一致，和当前的草案最大不同就是简写属性-webkit-border-radius的属性值也只有1个或2个值，意义和前面相同。</li>
<li>Chrome中圆角锯齿比较严重，基本上和Firefox2是同一水平，或许是它的webkit版本较低造成的。</li>
<li>由于webkit出生于khtml，所以把 上面属性中的webkit换成khtml即会得到以khtml为核心的浏览器支持的属性了。</li>
<li>当相邻的角半径之和大于所在矩形区域的大小时，都会直接设置所有的角半径为0，即圆角失效，而不会像Firefox那样同比率缩小。</li>
</ol>
</li>
<li>Opera尚不支持border-radius，虽然<a href="http://bbs.operachina.com/viewtopic.php?f=64&#038;t=36109">Opera10 alpha拥有众多的CSS3改进</a>，但是依旧看不到对其支持的希望。</li>
<li>IE就不用说了，标准的不支持了。从MSDN的<a href="http://msdn.microsoft.com/en-us/library/cc351024(VS.85).aspx#border">CSS Compatibility and Internet Explorer</a>中可以看出IE8已经铁定不支持了。</li>
</ol>
<h3>实际应用</h3>
<p>最简单的应用就是支持的用圆角，不支持的用方角。比如Wordpress2.7的后台、<a href="http://ued.koubei.com/">雅虎口碑UED的blog</a>和<a href="http://xiayu.info/">今天你带伞了吗?</a>。基础代码如下：</p>
<pre><code>
border-width: 1px;
border-style: solid;
-moz-border-radius: 11px;
-khtml-border-radius: 11px;
-webkit-border-radius: 11px;
border-radius: 11px;
</code></pre>
<p>实现请看<a href="http://dancewithnet.com/lab/2008/border-radius/" class="link-btn">演示实例</a>。</p>
<p><a href="http://snook.ca/archives/html_and_css/rounded_corners_experiment_ie/">利用VML可以实现从IE5-7的圆角</a>，但是貌似IE8不支持VML了。<a href="http://dillerdesign.com/experiment/DD_roundies/">组件DD_roundies</a>就是综合以上解决方案的一个具体应用。说实话这样实现出来的圆角也比较粗糙了，我感觉还不如不要。</p>
<p>像VML一样，Canvas也能实现圆角，切除了IE外，所有的主流浏览器都支持。所以就有了两者结合实现的组件<a href="http://labs.parkerfox.co.uk/cornerz/">Cornerz</a>。</p>
<p>如果上面的现实太痛苦，而又非要用圆角的话，要么一个像素一个像素去拼装，比如<a href="http://www.cssplay.co.uk/boxes/chunky.html">Chunky Borders</a>；要么就老老实实用图片来实现吧，比如<a href="http://www.lesliesommer.com/wdw07/html/">CSS Mojo</a>的方式。</p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2008/12/27/border-radius-and-rounded-corner/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>CSS Hacks</title>
		<link>http://dancewithnet.com/2008/07/12/css-hacks/</link>
		<comments>http://dancewithnet.com/2008/07/12/css-hacks/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 19:05:48 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[hack]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1347</guid>
		<description><![CDATA[Java一直标榜一句老话叫“编写一次，到处运行(Write Once,Run Anywhere)”，CSS也差一点点做到了。但就是为了差的一点点往往需要大量的工作，虽然这并不是CSS的错。基本上别妄想兼容所有的解析器... ]]></description>
			<content:encoded><![CDATA[<p>Java一直标榜一句老话叫“编写一次，到处运行(Write Once,Run Anywhere)”，CSS也差一点点做到了。但就是为了差的一点点往往需要大量的工作，虽然这并不是CSS的错。基本上别妄想兼容所有的解析器了，仅仅是为了让网页在<a href="http://developer.yahoo.com/yui/">YUI</a>中列举的<a href="http://developer.yahoo.com/yui/articles/gbs/index.html#gbschart">A级浏览器</a>呈现一致就不是一件特别容易的事情。虽然通过精心的组织HTML结构加上使用最合适最通用的CSS代码可能实现多浏览器呈现一致，但当在视觉的过度设计、精确到像素的规定和前端快速实现的要求的前提下，可能你不得不为不同的浏览器写不同的CSS代码，这就是CSS Hacks了。我们的目标是保持CSS简洁和没有CSS Hacks，但即使多年以前就呼吁<a href="http://www.digital-web.com/articles/keep_css_simple/">Keep CSS simple</a>的PPK也不得不在<a href="http://www.quirksmode.org/">他的网站</a>中使用CSS Hacks，即便如此其站点在所有的A级浏览器中也无法保持一致的呈现。所以，下面这个我常用的CSS Hacks列表或许有些用：<span id="more-1347"></span></p>
<table class="stat">
<tr>
<th></th>
<th>IE6</th>
<th>IE7</th>
<th>Firefox2+</th>
<th>Firefox3+</th>
<th>Opera9.5+</th>
<th>Safari3.1+</th>
</tr>
<tr>
<th>选择符{<br />
&nbsp;&nbsp;*属性:值;<br />
}<sup>[1]</sup></th>
<td>√</td>
<td>√</td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
</tr>
<tr>
<th>选择符{<br />
&nbsp;&nbsp;_属性:值;<br />
}</th>
<td>√</td>
<td>×<sup>[2]</sup></td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
</tr>
<tr>
<th>选择符,x:-moz-any-link{<br />
&nbsp;&nbsp;属性:值;<br />
}</th>
<td>×</td>
<td>√</td>
<td>√</td>
<td>√</td>
<td>×</td>
<td>×</td>
</tr>
<tr>
<th>选择符,x:-moz-any-link,x:default{<br />
&nbsp;&nbsp;属性:值;<br />
}</th>
<td>×</td>
<td>√</td>
<td>×</td>
<td>√</td>
<td>×</td>
<td>×</td>
</tr>
<tr>
<th>@media all and (min-width:0){<br />
&nbsp;&nbsp;选择符{属性:值;}<br />
}<sup>[3]</sup>
</th>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>√</td>
<td>√</td>
</tr>
<tr>
<th>@media all and (-webkit-min-device-pixel-ratio:0){<br />
&nbsp;&nbsp;选择符{属性:值;}<br />
}<sup>[4]</sup>
</th>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>×</td>
<td>√</td>
</tr>
</table>
<p>这里有一个<a href="http://dancewithnet.com/lab/2008/css-hacks/" class="link-btn">上述CSS Hacks的应用的例子</a>可以看看。</p>
<ul class="refer">
<li>[1]&nbsp;此处的*号其实也可以是.号、&gt;号、+号和#号。但它们都不属于CSS2.1规范合法属性名的一部分，所以不能通过验证。</li>
<li>[2]&nbsp;当IE7为<a href="http://hsivonen.iki.fi/doctype/">quriks mode</a>时和IE6为quriks mode解析相同，所以此时这个表达式在IE7中也能生效。<a href="http://wellstyled.com/css-underscore-hack.html">这个hack已经应用了很久了</a>，下划线_作为属性名的前缀是符合CSS2.1规范语法的，但不存在于其属性名列表中，所以依旧不能通过标准语法验证。对于多个IE的CSS Hacks，<a href="http://dancewithnet.com/2006/06/06/ie-conditional-comments/">条件注释</a>是一个很值得考虑的解决方案。另外对于IE8可以关注其新功能和变化，但现在考虑其CSS Hacks问题有点过早，真的有需求可以通过增加<a href="http://blogs.msdn.com/ie/archive/2008/06/10/introducing-ie-emulateie7.aspx">&lt;meta http-equiv=&#8221;X-UA-Compatible&#8221; content=&#8221;IE=EmulateIE7&#8243; /&gt;</a>来解决。</li>
<li>[3]&nbsp;如果把表达式中的and和(中间的空白去掉变成@media all and(min-width:0){选择符{属性:值;}}，那么Safari3+将无法识别，Opera9.5+则可以。</li>
<li>[4]&nbsp;这个表达式Opera9.0是支持的。</li>
</ul>
<p>上面这些CSS Hacks仅仅是沧海一粟，是一些简单的通用的CSS Hacks。这个世界上还存在很多很知名很经典的CSS Hacks，更多的CSS Hacks可以看这里：</p>
<ol>
<li><a href="http://paulirish.com/2009/browser-specific-css-hacks/">Browser CSS hacks</a></li>
<li><a href="http://www.nealgrosskopf.com/tech/thread.php?pid=20">CSS Browser Hacks For Firefox, Opera, Safari &#038; Internet Explorer</a></li>
<li><a href="http://perishablepress.com/press/2009/06/28/css-hacks-for-different-versions-of-firefox/">CSS Hacks for Different Versions of Firefox</a></li>
<li><a href="http://www.webdevout.net/css-hacks">CSS hacks</a></li>
<li><a href="http://css-discuss.incutio.com/?page=CssHack">CSS Hack</a></li>
<li><a href="http://centricle.com/ref/css/filters/">Will the browser apply the rule(s)?</a></li>
<li><a href="http://www.ericmeyeroncss.com/bonus/trick-hide.html">Tricking Browsers and Hiding Styles</a></li>
<li><a href="http://realazy.org/blog/2006/07/31/working-with-buggy-browsers-2/">与臭虫为友——浏览器补救办法，臭虫以及解决方案（第二部分）</a></li>
<li><a href="http://perishablepress.com/press/2008/07/15/css-hackz-series-targeting-and-filtering-internet-explorer-7/">CSS Hackz Series: Targeting and Filtering Internet Explorer 7</a></li>
<li><a href="http://www.virtuosimedia.com/tutorials/ultimate-ie6-cheatsheet-how-to-fix-25-internet-explorer-6-bugs">Ultimate IE6 Cheatsheet: How To Fix 25+ Internet Explorer 6 Bugs</a>&#8212;<a href="http://www.vfresh.org/w3c/727">中文版</a></li>
<li><a href="http://blog.gulu77.com/?p=59">CSS让你的IE浏览器崩溃</a></li>
<li><a href="http://haslayout.net/css/index">Internet Explorer CSS Bugs</a>&#8212;<a href="http://coolshell.cn/?p=1245">中文版</a></li>
<li><a href="http://www.css88.com/archives/579">【IE6的疯狂系列】IE6 BUG大全</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2008/07/12/css-hacks/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>是时候不用考虑基于字体大小（em）的设计了</title>
		<link>http://dancewithnet.com/2008/06/17/it-is-time-to-discard-font-size-adjustments/</link>
		<comments>http://dancewithnet.com/2008/06/17/it-is-time-to-discard-font-size-adjustments/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 18:23:35 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[em]]></category>
		<category><![CDATA[px]]></category>
		<category><![CDATA[全页面缩放]]></category>
		<category><![CDATA[可访问性]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1344</guid>
		<description><![CDATA[今天是Firefox3的2008下载日(貌似北京时间是6.18的凌晨1:00)，这就意味着Firefox3正式发布了。Firefox3有众多的改进和新功能，我最关注的功能之一是“全页面缩放（Full page zoom）”。这就意味着Firefox... ]]></description>
			<content:encoded><![CDATA[<p>今天是<a href="http://www.spreadfirefox.com/zh-CN/worldrecord">Firefox3的2008下载日</a>(貌似北京时间是6.18的凌晨1:00)，这就意味着Firefox3正式发布了。Firefox3有众多的<a href="http://xbeta.info/firefox3-new.htm">改进和新功能</a>，我最关注的功能之一是“<a href="http://blog.mozilla.com/seth/2008/06/09/fulll-page-zoom/">全页面缩放（Full page zoom）</a>”。这就意味着Firefox3和Opera以及IE7+都可以让用户“完全控制显示内容的大小同时自动调整页面布局和结构”，说白了就是可以让整个页面直接放大或缩小却不会乱掉。这就意味着我们不用再考虑为了可访问性而整个页面是基于字体大小（em）的设计了。<span id="more-1344"></span></p>
<p>在CSS中，有两种单位。一种是绝对长度单位，包括英寸(in)、厘米(cm)、毫米(mm)、点(pt)和派卡(pc)。另一种是相对长度单位，包括em、ex和像素(px)。ex由于在实际应用中需要获取x大小，因浏览器对此处理方式非常粗糙而被抛弃(更多内容可以参考Eric A. Meyer的《CSS权威指南》)，所以现在的网页设计中对大小距离的控制使用的单位是em和px（当然还有百分数值，但它必须是相对于另外一个值的）。</p>
<p>在css中，1个“em”定义为一种给定字体的font-size值。所以1em可能随元素的不同而不同，它会相对于父元素字体大小而改变。在常见浏览器下，默认字体的大小为16px。常见有两种方法来进行网页设计：</p>
<ol>
<li>设置默认字体大小为10px：
<pre><code>body{font-size:62.5%;}
#wrapper{width:97.4em;}</code></pre>
<p>这便于依次计算出其他元素的长宽值，比如某个容器#wrapper的宽度是974px，CSS中定义为97.4em。<a href="http://dancewithnet.com">本站随网之舞</a>就是依据这种方式来实现的。</li>
<li>设计默认字体大小为网页中最常用字体的大小，比如最常用字体的大小是12px：
<pre><code>body{font-size:75%;}
#wrapper{width:81.1667em;}
</code></pre>
<p>这样虽然省去了设置默认字体的大小，但是偶尔却为严格尺寸设计带来麻烦，比如你要设置那个宽为974px的容器#wrapper就会遇到此类麻烦。其实第一种方法也会遇到类似麻烦，只不过比第二种少些。
</li>
</ol>
<p>基于字体大小的设计好处很明显，当用户调整浏览器默认字体的大小时，字体和页面会随之缩放，能够满足挺这种方法的人常说的一个优点就是弱视的人可以通过放大字体来看清楚页面内容，增强了页面的可访问性。</p>
<p>每个屏幕都有分辨率，比如1280×1024分辨率时屏幕就有1280×1024个点，这每个点就是一个像素(px)。所以利用px来设计网页，不存在em那种相对于父元素字体大小变化而变化的问题。而实际上绝大部分的站点设计都是基于px设计的。在Windows平台下IE7之前都无法通过调整浏览器中的“字体大小”来调整文本大小，非IE浏览器可以，但实际上是一般基于px的页面，一旦仅仅调整了文本大小页面就会乱掉（在Firefox 2下观看除<a href="http://cn.yahoo.com/">中国雅虎</a>外的门户网站，调整一下字体大小就了解了）。</p>
<p>为了IE下不能调整以px为单位的字体大小，而非IE下可以的问题，<a href="http://developer.yahoo.com/yui/fonts/">YUI CSS Tools</a>采用了如下代码来设置默认1em的大小，支持用户的字体大小调整：</p>
<pre><code>body {font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}
</code></pre>
<p>为此IE默认情况下，1em的大小是13.3333px，所以你会看到<a href="http://developer.yahoo.com/yui/build/grids/grids.css">YUI CSS Grids</a>里面那些诸如<code>width:73.076em;</code>这样的值。</p>
<p>所以，基于字体大小（em）的设计和基于px的设计相比而言：</p>
<ol>
<li>基于字体大小(em)的设计页面带来的缩放效果有限，最早基于字体大小设计的门户网站应该就是<a href="http://www.yahoo.com/">Yahoo</a>和<a href="http://www.msn.com/">MSN</a>了，而实际上它们也仅仅是保证了上下缩放三级而已，再多就乱掉了。</li>
<li>现在的站点越来越多的图文混排，图像的高度和宽度本身就是像素数。除非你通过CSS来把图片的大小设置为相应的em值，就像本站的Logo这样，否则图片是不会随着文字变化而变化的。但是如果采用的是背景图片，那就基本上无计可施了。所以实际上基于字体大小来做图文混排设计的网页需要对图像的设计是有相当严格的要求的，即使如此仍无法完美解决，但复杂度却上升不少。</li>
<li>基于字体大小的网页设计，将使长度变得的非常的不直观，导致设置一个宽度变得非常麻烦，<a href="http://developer.yahoo.com/yui/build/grids/grids.css">YUI CSS Grids</a>中说明了这点。并且由于em会相对于父元素字体大小变化而变化的问题，导致图文混排的复杂设计时非常麻烦。特别是在盛行过度设计和精确到像素的这个浮躁时代。其实连<a href="http://google.com/">Google</a>和<a href="http://www.baidu.com/">百度</a>这种非常简单的首页都或多或少的利用px来布局。</li>
</ol>
<p>现在主流浏览器都支持了“全网页缩放”功能，<del datetime="2009-02-25T08:54:08+08:00">Safari尚未支持这个功能<ins datetime="2008-09-07T22:40:57+08:00">（Google的新推出的Chrome和Safari的基于同一个核心，很遗憾也不支持这个功能）</ins>，而是像Firefox2一样支持文本缩放，但是具有讽刺意味的是Apple页面基本上都是基于px的，所以一缩放就乱掉，我深信Safari支持这个功能仅仅是时间问题<ins datetime="2009-01-06T09:58:59+08:00">（<a href="http://webkit.org/blog/165/full-page-zoom/">Safari和Chrome共同核心引擎Webkit已经有计划了</a>）</ins></del><ins datetime="2009-02-25T09:54:08+08:00">Chrome2和Safari4都已经支持这个功能</ins>。两年前有篇<a href="http://jorux.com/archives/95-websites-of-china-need-to-rewrite-css/">《95%的中国网站需要重写CSS》</a>很流行，虽然保证用户的可访问性是应该的，但是应该找到其最佳实现的方法，毫无疑问浏览器的“全页面缩放”功能是最佳选择。从现在开始，基于px的设计不用再过于背负违背可用性的恶名了，基于em（文字大小）的设计不能给我们带来太多的好处，反而有可能耗费太多的精力挣扎于如何精确保护视觉设计上，设计师的精力应该更多的放在内容的理解、快速呈现、语义化、对屏幕阅读器的支持等等方面上。</p>
<p><a href="http://w3counter.com/globalstats.php">全球范围内IE6已经不到40%了</a>，中国用户比率应该高些，但趋势是一样的，毕竟IE8都出Beta了，IE6会很快成为历史的。如果你是偏执狂，需要考虑Firefox2和Safari的话，或许设置<code>body{font-size:10px;}</code>再基于em进行设计是一个不错的办法，<a href="http://cn.yahoo.com/">中国雅虎的首页</a>就是利用类似原理。总之，是时候不用考虑基于字体大小（em）的设计了，特别是针对IE6的解决方案。</p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2008/06/17/it-is-time-to-discard-font-size-adjustments/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>IE对CSS样式表的限制和解决方案</title>
		<link>http://dancewithnet.com/2008/04/22/a-solution-of-limit-of-style-tags-in-ie/</link>
		<comments>http://dancewithnet.com/2008/04/22/a-solution-of-limit-of-style-tags-in-ie/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 08:39:33 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[Javascript & DOM & AJAX]]></category>
		<category><![CDATA[@import]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[cssText]]></category>
		<category><![CDATA[document.styleSheet]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1281</guid>
		<description><![CDATA[HTML文档与CSS的关联常见有4种方式：


使用link标记
&#60;link rel="stylesheet" type="text/css" href="sheet.css" /&#62;


使用style元素
&#60;style type="text/css"&#62;
body{background:#fff;}
h1{font-size:2em;}
&#60;/style&#62;


使用@... ]]></description>
			<content:encoded><![CDATA[<p>HTML文档与CSS的关联常见有4种方式：</p>
<ol>
<li>
<p><strong>使用link标记</strong></p>
<pre><code>&lt;link rel="stylesheet" type="text/css" href="sheet.css" /&gt;</code></pre>
</li>
<li>
<p><strong>使用style元素</strong></p>
<pre><code>&lt;style type="text/css"&gt;
body{background:#fff;}
h1{font-size:2em;}
&lt;/style&gt;</code></pre>
</li>
<li>
<p><strong>使用@import指令</strong></p>
<pre><code>&lt;style type="text/css"&gt;
@import url(sheet1.css);
@import "sheet2.css";
&lt;/style&gt;</code></pre>
</li>
<li>
<p><strong>使用style属性的内联样式(inline style)</strong></p>
<pre><code>&lt;p style="color:#f00;"&gt;这是红色的字&lt;/p&gt;</code></pre>
</li>
</ol>
<p>在实际应用中，使用style属性的内联样式是不推荐使用的，XHTML1.1已经将其标准为不建议使用，原因很简单这种方式不比font标记强多少，削弱了CSS集中控制整个文档外观的优点。前3种方式利用了link标记和style标记，在IE(包括IE6、IE7和IE8 beta1)中有如下限制：<span id="more-1281"></span></p>
<ol>
<li>
<p><strong>文档中只有前31个link或style标记关联的CSS能够应用。</strong></p>
<p>从第32个开始，其标记关联的CSS都将失效。IE的官方文档<a href="http://support.microsoft.com/kb/262161/en-us">All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer</a>也提及这个限制，包括在使用.xsl的.xml文件也有这个限制。但是似乎写错了数量。请在IE看：</p>
<p><a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/index.html" class="link-btn">例1：34个style标记同时应用</a></p>
<p><a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/link.html" class="link-btn">例2：1个style标记和34个link标记同时应用</a></p>
</li>
<li>
<p><strong>一个style标记只有前31次<code>@import</code>指令有效应用。</strong></p>
<p>从第32个@import指令开始忽略。请看：</p>
<p><a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/import.html" class="link-btn">例3：在一个style标记中使用34次<code>@import</code>指令</a>。</p>
</li>
<li>
<p><strong>一个css文件只有前31次@import指令有效应用。</strong></p>
<p>从第31个@import指令开始忽略。请看：</p>
<p><a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/link-import.html" class="link-btn">例4：用link标记引入一个使用34次<code>@import</code>指令的css文件</a></p>
<p><a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/import-import.html" class="link-btn">例5：用style标记引入一个使用34次<code>@import</code>指令的css文件</a></p>
<p><a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/link-import-new.html" class="link-btn">例6：用link和style标记分别引入一个使用31次<code>@import</code>指令以上的css文件</a></p>
</li>
<li>
<p><del datetime="2009-09-10T23:45:30+08:00"><strong>一个CSS文件的不能超过288kb？</strong></del><ins datetime="2009-09-10T23:45:30+08:00"><a href="http://dancewithnet.com/2009/09/10/ie-css-4095-limit/">IE中每个style标签或css文件的选择符个数不能超过4095</a></ins></p>
<p><del datetime="2009-09-10T23:45:30+08:00">这个消息来自<a href="http://joshua.perina.com/africa/gambia/fajara/post/2008/1/25/internet-explorer-css-file-size-limit">Internet Explorer CSS File Size Limit</a>。</del></p>
</li>
<li>
<p><ins datetime="2008-05-05T00:13:37+08:00" cite="http://www.quirksmode.org/bugreports/archives/2005/02/Cascade_limit_via_import_rule.html"><strong>@import指令下层叠限制不能超过4层</strong></ins></p>
<p>在IE下通过@import指令引入css文件时，第5层会失效。这个限制来自<a href="http://www.quirksmode.org/bugreports/archives/2005/02/Cascade_limit_via_import_rule.html">Cascade limit via @import rule</a>。实际上，由于浏览器对多层嵌套的支持不完善，所以即使不得已使用了@import指令引入CSS文件，也不要超过2层。</p>
</li>
</ol>
<p>IE对CSS的限制在绝大部分情况下是不会遇到的，即使遇到最佳的解决方案也应该是手动或者通过后端程序对CSS文件和响应的标记进行合并，<a href="http://developer.yahoo.com/performance/rules.html#num_http">最小化的http请求数是优化页面呈现的第一原则</a>。</p>
<p>在IE中，可以通过<a href="http://msdn2.microsoft.com/en-us/library/ms535871.aspx"><code>document.styleSheets</code>对象</a>（Firefox、Opera9和Safari3.1都支持）修改内联和嵌入样式的值。该对象仅在文档包含style或link元素时可用，其实用<code>document.styleSheets.length</code>就可以看出IE下这个值最大是31。下面是利用Javascript来合并<code>link</code>和<code>style</code>标记来解决IE下的限制：</p>
<pre><code>var fnMergeStyleSheet = function(){
if(!document.styleSheets){
    return;
}
var aSheet = document.styleSheets,
    aStyle = document.getElementsByTagName('style'),
    aLink  = document.getElementsByTagName('link');
    if(aStyle.length + aLink.length < 32 || !aSheet[0].cssText){
        <span>//document.styleSheets.cssText 只有IE支持 </span>
        return;
    }
    var aCssText = [],aCloneLink = [];
    <span>//把style标签中的样式存入，然后删掉该标签，但保留第一个
    //因为由getElementsByTagName方法返回值是nodeList，所以删除时循环用倒序</span>
    for(var i=aStyle.length-1;i>-1;--i){
        var o = aStyle[i];
            aCssText.push(o.innerHTML);
            if(i>0){
                o.parentNode.removeChild(o);
            }
    }
    <span>//在IE中只有在31之内的link标签才能通过其styleSheet.cssText获取样式
    //无法的获取复制到一个数组aCloneLink中</span>
    for(var i=aLink.length-1;i>-1;--i){
       var o = aLink[i];
          if(o.getAttribute &#038;&#038; o.getAttribute('rel')==='stylesheet'){
               if(o.styleSheet){
                  aCssText.push(o.styleSheet.cssText);
               }else{
                   aCloneLink.push(o.cloneNode(true));
               }
               if(i>0){
                   o.parentNode.removeChild(o);
               }
          }
    }
    var oHead = document.getElementsByTagName('head')[0];
    <span>//通过前面的删除，前31个link或者style标记最多只剩下2个
    //通过重新增加link节点的方法激活其styleSheet属性，从而获取样式</span>
    for(var i = aCloneLink.length-1;i>-1;--i){
        var o = aCloneLink[i];
        oHead.appendChild(o);
        aCssText.push(o.styleSheet.cssText);
        oHead.removeChild(o);
    }
   <span>//把所有的样式都复制给第一个标签</span>
    aSheet[0].cssText += aCssText.join('');
}</code></pre>
<p>上面仅仅是一个简单的粗糙的解决方案，演示请看<a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/index.html" class="link-btn">例1</a>和<a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/link.html" class="link-btn">例2</a>，可以改进的地方还有：</p>
<ol>
<li>没有考虑<code>media</code>这个属性，如果有多个<code>media</code>应该分别合并，当然更没有考虑<code>link</code>标记的<code>rel="alternate stylesheet"</code>带来的影响。但我更建议通过<code>@media</code>指令把相应的样式写在同一个文件中，至少可以减少HTTP连接数。</li>
<li>没有解决@import指令31次限制的问题，其实可以提取其href值然后进行激活处理。但是实际应用在建议<a href="http://developer.yahoo.com/performance/rules.html#csslink">用<code>link</code>标记来替代@import指令</a>，因为在IE中<code>@import</code>指令相当与把link标记写在文档的底部，会导致在IE5/6页面加载时瞬间无样式问题，学名叫“Flash of Unstyled Content”（简称为FOUC）的bug，当然可以通过在文档头中放一个link或script元素可以避免这个bug。</li>
<li>一般来讲页面之所有出现大量的<code>link</code>或者<code>style</code>标签很可能有很多是相同的，可以在aCssText合并前除掉相同的项，减少代码量。</li>
</ol>
<p><ins datetime="2008-05-09T12:32:43+08:00"> 如果不用DOM中已存在的样式元素直接通过cssText属性添加样式代码，而是创建一个新的样式元素来添加，一定要注意先把新建的样式元素先添加到DOM中，然后再通过cssText属性添加样式代码。反之，其添加的样式代码似乎先被IE6的样式解析器解析后才添加，这样!imporant和hack都将失效。请看<a href="http://dancewithnet.com/lab/2008/a-solution-of-limit-of-style-tags-in-ie/hack.html" class="link-btn">例7</a>。不建议通过添加新的样式元素的方式来添加新的样式，这样很容易达到IE的限制条件。</ins></p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2008/04/22/a-solution-of-limit-of-style-tags-in-ie/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Firefox的默认样式表</title>
		<link>http://dancewithnet.com/2008/04/17/firefox-default-stylesheet/</link>
		<comments>http://dancewithnet.com/2008/04/17/firefox-default-stylesheet/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 16:31:10 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1280</guid>
		<description><![CDATA[每个浏览器都有自己的默认样式，这是一段预定义的CSS，用以简单地呈现网页。在Firefox中的地址栏中输入resource://gre/res/html.css即可以看到该浏览器的默认样式。在Firebug 1.2 Alphas的styles中就可以... ]]></description>
			<content:encoded><![CDATA[<p>每个浏览器都有自己的默认样式，这是一段预定义的CSS，用以简单地呈现网页。在Firefox中的地址栏中输入<a href="resource://gre/res/html.css">resource://gre/res/html.css</a>即可以看到该浏览器的默认样式。在<a href="http://www.getfirebug.com/releases/">Firebug 1.2 Alphas</a>的styles中就可以看到默认样式对页面定义样式的影响。毫无疑问，理解和学习浏览器的默认样式能更好的理解浏览器对解析样式和呈现页面。Firefox3和Firefox2相比，默认样式仅有8处不同，但这些改变也可以让我们感觉到Firefox3在样式上的改进：<span id="more-1280"></span></p>
<pre><code>@namespace url(http://www.w3.org/1999/xhtml); <span>/* set default namespace to HTML */</span>

<span>/* bidi */</span>

[dir="rtl"] {
  direction: rtl;
  unicode-bidi: embed;
}
[dir="ltr"] {
  direction: ltr;
  unicode-bidi: embed;
}
bdo[dir] {
  unicode-bidi: bidi-override;
}

<span>/* blocks */</span>

html, div, map, dt, isindex, form {
  display: block;
}

body {
  display: block;
  margin: 8px;
}

p, dl, multicol {
  display: block;
  margin: 1em 0;
}

dd {
  display: block;
  -moz-margin-start: 40px;
}

blockquote {
  display: block;
  margin: 1em 40px;
}

address {
  display: block;
  font-style: italic;
}

center {
  display: block;
  text-align: -moz-center;
}

blockquote[type=cite] {
  display: block;
  margin: 1em 0px;
  <span>/*** start:Firefox2 ***/</span>
  padding-left: 1em;
  border-left: solid;
  <span>/*** end:Firefox2 ***/</span>
  <span>/*** start:Firefox3 ***/</span>
  -moz-padding-start: 1em;
  -moz-border-start: solid;
  <span>/*** end:Firefox3 ***/</span>
  border-color: blue;
  border-width: thin;
}

span[_moz_quote=true] {
  color: blue;
}

pre[_moz_quote=true] {
  color: blue;
}

h1 {
  display: block;
  font-size: 2em;
  font-weight: bold;
  margin: .67em 0;
}

h2 {
  display: block;
  font-size: 1.5em;
  font-weight: bold;
  margin: .83em 0;
}

h3 {
  display: block;
  font-size: 1.17em;
  font-weight: bold;
  margin: 1em 0;
}

h4 {
  display: block;
  font-weight: bold;
  margin: 1.33em 0;
}

h5 {
  display: block;
  font-size: 0.83em;
  font-weight: bold;
  margin: 1.67em 0;
}

h6 {
  display: block;
  font-size: 0.67em;
  font-weight: bold;
  margin: 2.33em 0;
}

listing {
  display: block;
  font-family: -moz-fixed;
  font-size: medium;
  white-space: pre;
  margin: 1em 0;
}

xmp, pre, plaintext {
  display: block;
  font-family: -moz-fixed;
  white-space: pre;
  margin: 1em 0;
}

<span>/* tables */</span>

table {
  display: table;
  border-spacing: 2px;
  border-collapse: separate;
  margin-top: 0;
  margin-bottom: 0;
  <span>/* XXXldb do we want this if we're border-collapse:collapse ? */</span>
  -moz-box-sizing: border-box;
  text-indent: 0;
}

table[align="left"] {
  float: left;
}

table[align="right"] {
  float: right;
  text-align: start;
}

table[rules]:not([rules="none"]) {
  border-collapse: collapse;
}

<span>/* caption inherits from table not table-outer */</span>
caption {
  display: table-caption;
  text-align: center;
  -moz-box-sizing: border-box;
}

table[align="center"] >gt; caption {
  margin-left: auto;
  margin-right: auto;
}

table[align="center"] >gt; caption[align="left"] {
  margin-right: 0;
}

table[align="center"] >gt; caption[align="right"] {
  margin-left: 0;
}

tr {
  display: table-row;
  vertical-align: inherit;
}

col {
  display: table-column;
}

colgroup {
  display: table-column-group;
}

tbody {
  display: table-row-group;
  vertical-align: middle;
}

thead {
  display: table-header-group;
  vertical-align: middle;
}

tfoot {
  display: table-footer-group;
  vertical-align: middle;
}

<span>/* for XHTML tables without tbody */</span>
table >gt; tr {
  vertical-align: middle;
}

td {
  display: table-cell;
  vertical-align: inherit;
  text-align: inherit;
  padding: 1px;
}

th {
  display: table-cell;
  vertical-align: inherit;
  font-weight: bold;
  padding: 1px;
}

tr >gt; form:-moz-is-html, tbody >gt; form:-moz-is-html,
thead >gt; form:-moz-is-html, tfoot >gt; form:-moz-is-html,
table >gt; form:-moz-is-html {
  <span>/* Important: don't show these forms in HTML */</span>
  display: none !important;
}

<span>/* inlines */</span>

q:before {
  content: open-quote;
}

q:after {
  content: close-quote;
}

b, strong {
  font-weight: bolder;
}

i, cite, em, var, dfn {
  font-style: italic;
}

tt, code, kbd, samp {
  font-family: -moz-fixed;
}

u, ins {
  text-decoration: underline;
}

s, strike, del {
  text-decoration: line-through;
}

blink {
  text-decoration: blink;
}

big {
  font-size: larger;
}

small {
  font-size: smaller;
}

sub {
  vertical-align: sub;
  font-size: smaller;
  line-height: normal;
}

sup {
  vertical-align: super;
  font-size: smaller;
  line-height: normal;
}

nobr {
  white-space: nowrap;
}

<span>/* titles */</span>
abbr[title], acronym[title] {
  border-bottom: dotted 1px;
}

<span>/* lists */</span>

ul, menu, dir {
  display: block;
  list-style-type: disc;
  margin: 1em 0;
  -moz-padding-start: 40px;
}

ol {
  display: block;
  list-style-type: decimal;
  margin: 1em 0;
  -moz-padding-start: 40px;
}

li {
  display: list-item;
  <span>/** start:Firefox2 **/</span>
  -moz-float-edge: margin-box;
  <span>/** end:Firefox2 **/</span>
}

<span>/* nested lists have no top/bottom margins */</span>
ul ul,   ul ol,   ul dir,   ul menu,   ul dl,
ol ul,   ol ol,   ol dir,   ol menu,   ol dl,
dir ul,  dir ol,  dir dir,  dir menu,  dir dl,
menu ul, menu ol, menu dir, menu menu, menu dl,
dl ul,   dl ol,   dl dir,   dl menu,   dl dl {
  margin-top: 0;
  margin-bottom: 0;
}

<span>/* 2 deep unordered lists use a circle */</span>
ol ul,   ul ul,   menu ul,   dir ul,
ol menu, ul menu, menu menu, dir menu,
ol dir,  ul dir,  menu dir,  dir dir {
  list-style-type: circle;
}

<span>/* 3 deep (or more) unordered lists use a square */</span>
ol ol ul,     ol ul ul,     ol menu ul,     ol dir ul,
ol ol menu,   ol ul menu,   ol menu menu,   ol dir menu,
ol ol dir,    ol ul dir,    ol menu dir,    ol dir dir,
ul ol ul,     ul ul ul,     ul menu ul,     ul dir ul,
ul ol menu,   ul ul menu,   ul menu menu,   ul dir menu,
ul ol dir,    ul ul dir,    ul menu dir,    ul dir dir,
menu ol ul,   menu ul ul,   menu menu ul,   menu dir ul,
menu ol menu, menu ul menu, menu menu menu, menu dir menu,
menu ol dir,  menu ul dir,  menu menu dir,  menu dir dir,
dir ol ul,    dir ul ul,    dir menu ul,    dir dir ul,
dir ol menu,  dir ul menu,  dir menu menu,  dir dir menu,
dir ol dir,   dir ul dir,   dir menu dir,   dir dir dir {
  list-style-type: square;
}

<span>/* leafs */</span>

<span>/* <lt;hr>gt; noshade and color attributes are handled completely by
 * the nsHTMLHRElement attribute mapping code
 */</span>
hr {
  display: block;
  height: 2px;
  <span>/** start:Firefox2 **/</span>
  border: 1px -moz-bg-inset;
  <span>/** end:Firefox2 **/</span>
  <span>/** start:Firefox3 **/</span>
  border: 1px inset;
  <span>/** end:Firefox3 **/</span>
  margin: 0.5em auto 0.5em auto;
  <span>/** start:Firefox3 **/</span>
  color: gray;
  <span>/** end:Firefox3 **/</span>
  -moz-float-edge: margin-box;
  -moz-box-sizing: border-box;
}

hr[size="1"] {
  <span>/** start:Firefox2 **/</span>
  border-style: -moz-bg-solid none none none;
  <span>/** end:Firefox2 **/</span>
  <span>/** start:Firefox3 **/</span>
  border-style: solid none none none;
  <span>/** end:Firefox3 **/</span>
}

*|*:-moz-any-link img, img[usemap], object[usemap] {
  border: 2px solid;
}

<span>/** start:Firefox3 **/</span>
img:-moz-broken::before, input:-moz-broken::before,
img:-moz-user-disabled::before, input:-moz-user-disabled::before,
img:-moz-loading::before, input:-moz-loading::before,
applet:-moz-empty-except-children-with-localname(param):-moz-broken::before,
applet:-moz-empty-except-children-with-localname(param):-moz-user-disabled::before {
  content: -moz-alt-content !important;
  unicode-bidi: embed;
}

object:-moz-broken >gt; *|*, applet:-moz-broken >gt; *|*
object:-moz-user-disabled >gt; *|*, applet:-moz-user-disabled >gt; *|* {
  <span>/*
    Inherit in the object's alignment so that if we aren't aligned explicitly
    we'll end up in the right place vertically.  See bug 36997.  Note that this
    is not !important because we _might_ be aligned explicitly.
  */</span>
  vertical-align: inherit;
}

img:-moz-suppressed, input:-moz-suppressed, object:-moz-suppressed,
embed:-moz-suppressed, applet:-moz-suppressed {
  <span>/*
    Set visibility too in case the page changes display.  Note that we _may_
    want to just set visibility and not display, in general, if we find that
    display:none breaks too many layouts.  And if we decide we really do want
    people to be able to right-click blocked images, etc, we need to set
    neither one, and hack the painting code.... : (
   */</span>
  display: none !important;
  visibility: hidden !important;
}
<span>/** end:Firefox3 **/</span>  

img[usemap], object[usemap] {
  color: blue;
}

frameset {
  display: block ! important;
  overflow: -moz-hidden-unscrollable;
  position: static ! important;
  float: none ! important;
  border: none ! important;
}

frame {
  border: none ! important;
}

iframe {
  border: 2px inset;
}

noframes {
  display: none;
}

spacer {
  position: static ! important;
  float: none ! important;
}

canvas {
  -moz-user-select: none;
}

<span>/* focusable content: anything w/ tabindex >gt;=0 is focusable */</span>
abbr:focus, acronym:focus, address:focus, applet:focus, b:focus,
base:focus, big:focus, blockquote:focus, br:focus, canvas:focus, caption:focus,
center:focus, cite:focus, code:focus, col:focus, colgroup:focus, dd:focus,
del:focus, dfn:focus, dir:focus, div:focus, dl:focus, dt:focus, em:focus,
fieldset:focus, font:focus, form:focus, h1:focus, h2:focus, h3:focus, h4:focus,
h5:focus, h6:focus, hr:focus, i:focus, img:focus, ins:focus,
kbd:focus, label:focus, legend:focus, li:focus, link:focus, menu:focus,
object:focus, ol:focus, p:focus, pre:focus, q:focus, s:focus, samp:focus,
small:focus, span:focus, strike:focus, strong:focus, sub:focus, sup:focus,
table:focus, tbody:focus, td:focus, tfoot:focus, th:focus, thead:focus,
tr:focus, tt:focus, u:focus, ul:focus, var:focus {
  <span>/** start:Firefox2 **/</span>
   outline: 1px dotted invert;
  <span>/** end:Firefox2 **/</span>
  <span>/** start:Firefox3 **/</span>
  <span>/* Don't specify the outline-color, we should always use initial value. */</span>
   outline: 1px dotted;
  <span>/** end:Firefox3 **/</span>
}

<span>/* hidden elements */</span>
area, base, basefont, head, meta, script, style, title,
noembed, param {
   display: none;
}

<span>/* emulation of non-standard HTML <lt;marquee>gt; tag */</span>
marquee {
  <span>/** start:Firefox2 **/</span>
  display: block;
  <span>/** end:Firefox2 **/</span>
  <span>/** start:Firefox3 **/</span>
  width: -moz-available;
  display: inline-block;
  vertical-align: text-bottom;
  text-align: start;
  <span>/** end:Firefox3 **/</span>
  -moz-binding: url('chrome://xbl-marquee/content/xbl-marquee.xml#marquee-horizontal');
}

marquee[direction="up"], marquee[direction="down"] {
  -moz-binding: url('chrome://xbl-marquee/content/xbl-marquee.xml#marquee-vertical');
  height: 200px;
}

<span>/* PRINT ONLY rules follow */</span>
@media print {

  marquee { -moz-binding: none; }

  <span>/* XXX this should not be necessary, we should be stopping blinking
     of any kind in print preview, not just the <lt;blink>gt; element */</span>
  blink {
    text-decoration: none;
  }

}</code></pre>
<p>虽然CSS2.1的附录里给了<a href="http://www.w3.org/TR/CSS21/sample.html">HTML4默认样式的建议(Appendix D. Default style sheet for HTML 4)</a>，这本身就不是一个很完美的解决方案，加上各个浏览器附加上一点自己私有的属性，Firefox默认样式表中清楚的说明了这点，导致了各个浏览器的默认样式表不尽相同，比如对比这份参考CSS2.1的对HTML4默认样式的建议通过实践总结出来的<a href="http://gabrieleromanato.altervista.org/css-test/internet-explorer-6-default-style-sheet/index.html">IE6的默认样式表(INTERNET EXPLORER 6 DEFAULT STYLE SHEET)</a>。解决这个问题的常见方法就是通过一个通用的CSS文件来重置HTML标签的样式，使其在各个浏览器中表现的一样，比如<a href="http://developer.yahoo.com/yui/reset/">YUI Reset CSS</a>和Eric Meyer的<a href="http://meyerweb.com/eric/tools/css/reset/">CSS Tools: Reset CSS</a>就是很好的解决方案。</p>
<p>扩展阅读：<a href="http://meyerweb.com/eric/thoughts/2004/09/15/emreallyem-undoing-htmlcss/">Really Undoing html.css</a> &#8211; Eric Meyer</p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2008/04/17/firefox-default-stylesheet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>display:inline-block的应用两例</title>
		<link>http://dancewithnet.com/2008/04/05/examples-of-display-inline-block/</link>
		<comments>http://dancewithnet.com/2008/04/05/examples-of-display-inline-block/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 01:17:49 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[-moz-inline-box]]></category>
		<category><![CDATA[-moz-inline-stack]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Firefox2]]></category>
		<category><![CDATA[inline-block]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/?p=1276</guid>
		<description><![CDATA[CSS的display有属性值inline-block{display:inline-block;}，下面是应用其来实现用图片替代文字的两个例子：
请看例一。
Markup：
&#60;i class=&#34;arrow-1 replacement&#34;&#62;箭头1&#60;/i&#62;
&#60;a href=&#34;http://dancewi... ]]></description>
			<content:encoded><![CDATA[<p><a href="http://dancewithnet.com/2007/10/30/css-display-inline-block/">CSS的display有属性值inline-block{display:inline-block;}</a>，下面是应用其来实现用图片替代文字的两个例子：</p>
<p>请看<a href="http://dancewithnet.com/lab/2008/examples-of-display-inline-block/#demo-1" class="link-btn">例一</a>。</p>
<p><strong>Markup</strong>：</p>
<pre><code>&lt;i class=&quot;arrow-1 replacement&quot;&gt;箭头1&lt;/i&gt;
&lt;a href=&quot;http://dancewithnet.com&quot; class=&quot;arrow-2 replacement&quot;&gt;箭头2&lt;/a&gt;
&lt;p class=&quot;arrow-3 replacement&quot;&gt;箭头3&lt;/p&gt;</code></pre>
<p><strong>CSS</strong>：<span id="more-1276"></span></p>
<pre><code><span>/* start:arrow */</span>
.replacement{
    display:inline-block;<span>/* Firefox3 beta、IE8 beta、Opera、Safari支持*/</span>
    display:-moz-inline-stack;<span>/* Firefox的私有属性，也可以用-moz-inline-box */</span>
    *display:inline;
    zoom:1;<span>/* 这两行，激活IE6/7的layout，实现类似效果 */</span>
    line-height:9999em;
    overflow:hidden;<span>/* 上面两行，隐藏因设置容器大小而溢出的文字，对Firefox2无效 */</span>
    font-size:0;<span>/* 解决上面两行代码在Firefox2下无法隐藏溢出文字*/</span>
    <span>/*
      * 上面是综合<a href="http://www.planabc.net/">怿飞</a>给出清除溢出文字新方法后的方案，下面是以前的方案
      */</span>
    <del datetime="2008-04-08T17:21:01+08:00">text-indent:-9999px; <span>/* 隐藏文字，Safari和Opera下无法仅用{font-size:0;}来解决 */</span>
    overflow:hidden;<span>/* 上面两行，隐藏因设置容器大小而溢出的文字，对Firefox2无效 */</span>
    font-size:0;<span>/* 解决上面两行代码在Firefox2下无法隐藏溢出文字(谢谢<a href="http://www.planabc.net/">怿飞</a>)*/</span>
    *text-indent:0;
    <span>/* 解决IE6/7下text-indent:-9999px的bug，
     &lt;p&gt;&lt;a style=&quot;text-indent:-9999px;&quot; class=&quot;replacement&quot;&gt;箭头&lt;/a&gt;文字&lt;/p&gt;
     相当于
     &lt;p style=&quot;text-indent:-9999px;&quot;&gt;&lt;a  class=&quot;replacement&quot;&gt;箭头&lt;/a&gt;文字&lt;/p&gt;
      导致整段文字的消失，而当该链接前面有文字时则没有问题，如：
      &lt;p&gt;文字&lt;a  class=&quot;replacement&quot; style=&quot;text-indent:-9999px;&quot;&gt;箭头&lt;/a&gt;文字&lt;/p&gt;
    */</span>
    line-height:0;<span>/* 解决{text-indent:0;font-size:0;}时，IE下文字还留下一条横线的bug  */</span> </del>

    vertical-align:middle;<span>/* 行内垂直居中，对Opera有特殊意义，其和文字混排偏移有点离谱 */</span>

    <span>/*default for arrow-1*/</span>
    width:6px;
    height:12px;
    background:url(signs.png) no-repeat 0 -360px;
}
<del datetime="2008-04-08T10:09:12+08:00">.replacement i{
    <span>/*display:none;*/</span>
    <span>/*visibility:hidden;*/</span>
    display:block;
     <span>/* 因为Firefox2的原因，配合里面的i标签，用来实现文本的隐藏。
               如果用注释部分的任意一个，可以删掉.replacement中的text-indent:-9999px;  */</span>
}</del>
.arrow-1{
}
.arrow-2{
    width:8px;
    background-position:0 -500px;
}
.arrow-3{
    width:14px;
    background-position:0 -580px;
}
<del datetime="2008-04-08T10:09:12+09:00">.only-ff2{
    padding-left:9999px;
    <span>/* 解决单标签下Firefox2下无法隐藏文本问题，
                 但是对其他版本浏览器都造成巨大影响，不可取 */</span>
}</del>
<span>/* end:arrow */</span>
</code></pre>
<p><a href="http://dancewithnet.com/lab/2008/examples-of-display-inline-block/#demo-2" class="link-btn">例二</a>是例一的一个较复杂的应用。</p>
<p>在这个应用中可以发现<code>-moz-inline-box</code>和<code>-moz-inline-stack</code>的区别，比如把例二中<code>-moz-inline-stack</code>改成<code>-moz-inline-stack</code>。在实际应用中<code>-moz-inline-box</code>会存在元素间的对齐等问题，虽然Firefox还有一个私有属性<a href="http://developer.mozilla.org/en/docs/Mozilla_CSS_Extensions#-moz-box-align">-moz-box-align</a>来帮助解决对齐问题，但依旧难以预料问题多多，而相对来说<code>-moz-inline-stack</code>的表现更像<code>inline-block</code>，这点可以在Firefox3中测试出来。但<code>-moz-inline-stack</code>使用时也会有一个bug，如果一个{display:-moz-inline-stack;}的元素外层元素是{display:inline;}即会使Firefox中其包含的链接不可点，这个需要用<code>{position:relative;}</code>来解决（谢谢<a href="http://hi.baidu.com/dcpl/">乌龙茶</a>）：</p>
<pre><code>ul.pagination{
    display:inline;
}
ul.pagination li{
    display:inline-block;
    display:-moz-inline-stack;
    *display:inline;
    zoom:1;
    *margin:0 3px;
    vertical-align:middle;
    _vertical-align:bottom;
    position:relative;
    <span>/* 解决因为ul的{display:inline;}问题导致Firefox中li里面的链接不可点的bug */</span>
    *position:static;
    <span>/* 解决因为IE6中因为上一行代码带来在{position:relative}容器中移位在bug */</span>
}</code></pre>
<p>更多Firefox的私有属性可以看<a href="http://developer.mozilla.org/en/docs/CSS_Reference:Mozilla_Extensions">CSS Reference:Mozilla Extensions</a>和<a href="http://developer.mozilla.org/en/docs/Mozilla_CSS_Extensions">Mozilla CSS Extensions</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2008/04/05/examples-of-display-inline-block/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>CSS{display:inline-block}</title>
		<link>http://dancewithnet.com/2007/10/30/css-display-inline-block/</link>
		<comments>http://dancewithnet.com/2007/10/30/css-display-inline-block/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 14:02:15 +0000</pubDate>
		<dc:creator>秦歌</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[inline-block]]></category>

		<guid isPermaLink="false">http://dancewithnet.com/2007/10/30/css-display-inline-block/</guid>
		<description><![CDATA[2002年W3C推出CSS2.1规范时，给元素的display属性增加了inline-block值。其作用是“这个值导致一个元素产生一个块状盒模型（block box），而本身作为单一的内联盒模型（inline box）流动排列（flow），... ]]></description>
			<content:encoded><![CDATA[<p>2002年W3C推出CSS2.1规范时，<a href="http://www.w3.org/TR/CSS21/visuren.html#display-prop">给元素的display属性增加了inline-block值</a>。其作用是“这个值导致一个元素产生一个块状盒模型（block box），而本身作为单一的内联盒模型（inline box）流动排列（flow），类似一个被替代的元素。Display值为inline-block的元素内部形成一个块状盒模型，而本身形成类似一个内联的被替代元素”<sup>[1]</sup>。即display为inline-block的元素既可以像块状元素一样定义高度宽度，又可以和内联元素（比如文字）排列在一行。</p>
<p>这个效果在页面设计的时候，很多地方都可以带来便利，最常见的莫过于设计导航时，既可以像inline元素那样实现居中，又可以设置像block元素那样设置单个菜单大小，还可以通过text-indent来隐藏文字显示背景图片。请看&nbsp;<a href="http://dancewithnet.com/lab/2007/10/display-inline-block/" class="link-btn">演示实例&gt;&gt;&gt;&gt;</a><span id="more-1145"></span>。</p>
<ol>
<li>Opera和Safari支持这个属性。</li>
<li><del datetime="2008-04-04T03:42:32+08:00">IE不支持这个属性</del><ins datetime="2008-04-04T03:42:32+08:00">IE8 beta1支持这个属性</ins>，但inline-block会触发<a href="http://www.satzansatz.de/cssd/onhavinglayout.html">IE的layout</a>，从而使内联元素具有类似inline-block元素的属性。<a href="http://www.hedgerwow.com/360/dhtml/css-display-inline.html">cross-browser : display:inline-block</a>是一个很好的例子。<br />
对于display:block的元素，要实现类似inline-block的效果，可以先触发layout，再设置为inline，需要注意的是这两个display必须在两个CSS声明中才有效，代码如下：</p>
<pre><code>.pagination li{
    display:inline-block;
}
.pagination li{
    display:inline;
}
</code></pre>
<p>或者直接设置为inline，再利用zoom来触发layout来实现类似效果：</p>
<pre><code>.pagination li{
    display:inline;
    zoom:1;
}
</code></pre>
</li>
<li>Firefox也不支持这个，这个是蛮意外的事情，<del datetime="2008-01-21T15:19:16+00:00">Firefox3应该会支持吧</del>，<ins datetime="2008-01-21T15:19:16+00:00">Firefox3 beta2上已经正式支持</ins>，在这之前可以利用其私有属性{display:-moz-inline-box}来实现类似效果是一个不错的选择<sup>[2]</sup>。</li>
</ol>
<ul class="refer">
<li>[1]&nbsp;W3C的对<a href="http://www.w3.org/TR/CSS21/visuren.html#display-prop">inline-block英文定义</a>是“This value causes an element to generate a block box, which itself is flowed as a single inline box, similar to a replaced element. The inside of an inline-block is formatted as a block box, and the element itself is formatted as an inline replaced element.”</li>
<li>[2]&nbsp;<del datetime="2007-11-02T18:25:00+08:00"><a href="http://bolm.cn/blog/?p=38">display:inline-block深入探究</a></del><ins datetime="2007-11-02T18:25:00+08:00" title="真正的原文"><a href="http://www.planabc.net/article.asp?id=118">display:inline-block的深入理解</a></ins></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dancewithnet.com/2007/10/30/css-display-inline-block/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

